Read this in other languages: 中文
JSONA = JSON + Annotation. JSON describes the data, Annotation describes the logic.
The examples below cover all the features of JSONA.
/*
multiple line comment
*/
// single line comment
{
@foo /* abc */ @optional
@null(null) // single line comment
@bool(true)
@float(3.14)
@number(-3)
@string('abc "def" ghi')
@array([3,4])
@object({
k1: "v1",
k2: "v2",
})
nullValue: /* xyz */ null,
boolTrue: true,
boolFalse: false,
float: 3.14,
floatNegative: -3.14,
floatNegativeWithoutInteger: -.14,
floatNegativeWithoutDecimal: -3.,
integer: 3,
hex: 0x1a,
binary: 0b01,
octal: 0o12,
integerNegative: -3,
stringSingleQuota: 'abc "def" ghi',
stringDoubleQuota: "abc 'def' ghi",
stringBacktick: `abc
def \`
xyz`,
stringEscape1: '\0\b\f\n\r\t\u000b\'\\\xA9\u00A9\u{2F804}',
stringEscape2: "\0\b\f\n\r\t\u000b\'\\\xA9\u00A9\u{2F804}",
stringEscape3: `\0\b\f\n\r\t\u000b\'\\\xA9\u00A9\u{2F804}`,
arrayEmpty: [],
arrayEmptyMultiLine: [ @array
],
arrayEmptyWithAnnotation: [], // @array
arraySimple: [ @array
"a", @upper
"b",
],
arrayOnline: ["a", "b"], @array
arrayExtraComma: ["a", "b",],
objectEmpty: {},
objectEmptyMultiLine: { @object
},
objectEmptyWithAnnotation: {}, @use("Object4")
objectSimple: { @save("Object4")
k1: "v1", @upper
k2: "v2",
},
objectOneLine: { k1: "v1", k2: "v2" }, @object
objectExtraComma: { k1: "v1", k2: "v2", },
}
JSONA is a superset of JSON, borrowing the syntax of ECMAScript to alleviate some of the limitations of JSON.
/**
multiple lines comment
*/
// single line comment
{
@anno /* inline comment */ @anno
}
{
"a": 1,
b: 2,
'a': 3,
`a`: 4,
}
{
a: 3,
b: 4,
c: [
'x',
'y',
],
}
{
a: 3.,
b: .1,
c: 3.1,
}
{
integer: 3,
hex: 0x1a,
binary: 0b01,
octal: 0o12,
}
{
x: 'abc "def" ghi',
y: "abc 'def' ghi",
z: `abc "def", 'ghi'`,
}
{
x: `abc
def`
}
{
x: '\0\b\f\n\r\t\u000b\'\\\xA9\u00A9\u{2F804}', // single quote
y: "\0\b\f\n\r\t\u000b\'\\\xA9\u00A9\u{2F804}", // double quote
z: `\0\b\f\n\r\t\u000b\'\\\xA9\u00A9\u{2F804}`, // backtick quote
}
Annotations are marked with @
followed by a variable name. Annotations may or may not have value.
Here's a list of where all the annotations are in JSONA:
{ @anno
@anno
v1: 1, @anno
v2: {}, @anno
v3: [], @anno
v4: [ @anno
],
v5: [
@anno
],
v6: [
], @anno
} @anno
@anno
Annotation values must be enclosed in parentheses, but can be omitted.
Annotation values must be valid but no annotation JSONA, annotation values cannot nest annotation values.
@anno
@anno(null)
@anno(true)
@anno('a')
@anno(3)
@anno(0.3)
@anno([])
@anno(['a'])
@anno({})
@anno({a:3})
- jsona - JSONA Toolbox, includes parser, cli, lsp.
- apitest - declarative api testing tool.
- jsona-openapi - write openapi in jsona.
- vscode-jsona - vscode extension for jsona.