JavaScript-ish Object Notation - A superset of JSON with comments, single quote strings, unquoted property names, trailing commas, and other quality of life features
jsion.ts
- TypeScript source for JSION
// JSION TypeScript API
namespace JSION {
const transpile: (text: string) => string;
const parse: typeof JSON.parse;
const stringify: typeof JSON.stringify;
}
jsion.js
- Ready to use JavaScript- More languages coming soon...
JSION adds the following features to standard JSON.
Text between (*
and *)
is treated as a comment. Comments may be placed anywhere except inside of string keys and values. To include a *)
in a comment, escape the asterisk it with a backslash. JSION has no single line comments since it may be minified just like JSON.
{
(* User Profile (v1.0.0) *)
"name": "Trinity",
"admin": true (* Does user have admin powers? *)
}
If a property name is a simple JavaScript-like identifier ([a-zA-Z_$][0-9a-zA-Z_$]*
), the surrounding quotes may be omitted.
{
name: "Trinity",
nickname: "Trin"
}
Just like in JavaScript, trailing commas after a value are ignored in objects and arrays.
{
"activity": [
"2021",
"2022",
"2024",
],
}
Strings (as both keys and values) can use single quotes instead of double quotes. When using single quotes, double quotes do not need to be escaped, but internal single quotes do.
{
'recent posts': [
'"π₯ Heat from fire..."',
"\"Hello World!\"",
'"Isn\'t this cool?"'
]
}
Single underscores can be placed within numbers between digits to improve readability. Underscores may not directly precede or follow a decimal point or an e
or E
if using exponential notation.
{
"points": 1_000_000
}
JSION supports hexadecimal, octal, and binary integer literals. These all support the aforementioned numeric separators.
{
"colors": [
0xAD4674,
0xC8_7F_93,
0o74571362,
0b111001001101001011000110,
0b0111_1011_0100_1100_0011_1010
]
}
One or more question marks may be used in place of null
.
{
"profile picture": ???
}
Missing values in objects and arrays are interpreted as null. Note that trailing comma removal in arrays happens after!
{
"alt text": ,
"icons": [,"admin",,,"flower",,]
}
JSION | JSON | |
---|---|---|
Expanded | {
(* User Profile (v1.0.0) *)
name: 'Trinity',
nickname: 'Trin',
admin: true (* Does user have admin powers? *),
activity: [
"2021", "2022", "2024",
],
'recent posts': [
'"π₯ Heat from fire..."',
"\"Hello World!\"",
'"Isn\'t this cool?"',
],
points: 1_000_000,
colors: [
0xAD4674,
0xC8_7F_93,
0o74571362,
0b111001001101001011000110,
0b0111_1011_0100_1100_0011_1010,
],
"profile picture": ???,
"alt text": ,
icons: [,"admin",,,"flower",,],
} |
{
"name": "Trinity",
"nickname": "Trin",
"admin": true ,
"activity": [
"2021", "2022", "2024"
],
"recent posts": [
"\"π₯ Heat from fire...\"",
"\"Hello World!\"",
"\"Isn't this cool?\""
],
"points": 1000000,
"colors": [
11355764,
13139859,
15921906,
14996166,
8080442
],
"profile picture": null,
"alt text": null,
"icons": [null,"admin",null,null,"flower",null]
} |
Minified | {(*User Profile (v1.0.0)*)name:'Trinity',
nickname:'Trin',admin:true(*Does user have admin
powers?*),activity:["2021","2022","2024"],
'recent posts':['"π₯ Heat from fire..."',
"\"Hello World!\"",'"Isn\'t this cool?"'],points:
1000000,colors:[0xAD4674,0xC8_7F_93,0o74571362,
0b111001001101001011000110,0b011110110100110000111010
],"profile picture":,"alt text":,"icons":[,"admin",,,
"flower",,]} |
{"name":"Trinity","nickname":"Trin",
"admin":true,"activity":["2021","2022","2024"],
"recent posts":["\"π₯ Heat from fire...\"",
"\"Hello World!\"","\"Isn't this cool?\""],
"points":1000000,"colors":[11355764,13139859,
15921906,14996166,8080442],"profile picture":null,
"alt text":null,"icons":[null,"admin",null,null,
"flower",null]} |
- JSION is designed for easier human use (like config files); when exchanging between machines, use JSON
- JSION should work the same regardless of being minified or expanded
- JSION must be a superset of JSON (All valid JSON is valid JSION and has the same meaning)
- Optimizations
- Allow semicolons to be used in place of commas
- Optional commas in objects
- Expand the stringify method to support inserting comments
- Expand the stringify method to use shorter space saving formats when possible
- Improve error messages
- Additional number formats for positive signs and more