JavaScript-ish Object Notation - JSON with comments, single quote strings, unquoted property names, trailing commas, and other quality of life features
jsion.ts
- TypeScript source for JSIONjsion.js
- Ready to use JavaScript- More languages coming soon...
Aside from the following features, JSION is identical to standard JSON.
Text between (
and )
is treated as a comment. Comments may be place anywhere except inside of string keys and values. To include a )
in a comment, escape it with a backslash.
{
(User Profile (v1.0.0\))
"name": "Trinity",
"active": true (Signed in recently?)
}
Property names starting with a letter, an underscore, or a dollar sign followed by only other alphanumeric characters, dollar signs, and underscores do not need to be placed in quotes. This is similar to JavaScript except that higher Unicode letters and zero width spaces are not allowed.
{
name: "Trinity",
nickname: "Trin",
"contact info": {
phone_number: "+10000000000",
email_address: "[email protected]"
}
}
Just like in JavaScript, trailing commas after a value are valid in objects and arrays.
{
"favorite colors": [
"#5ED7FF",
"#F970FF",
"#F7F7F7",
],
"contact info": {
"phone_number": "+10000000000",
"email_address": "[email protected]",
},
}
Strings (keys and values) can use single quotes ('
) instead of double quotes ("
). When using single quotes, double quotes do not need to be escaped.
{
'name': 'Trinity',
'favorite colors': [
'#5ED7FF'
'#F970FF'
'#F7F7F7'
],
'quotes': [
'"I like cake 🎂"',
"\"Hello World!\"",
'"Isn\'t this cool?"'
]
}
Underscores (_
) can be placed within numbers to improve readability. Underscores may not directly precede or follow a decimal point or an e
or E
if using exponential notation.
{
"id": 1_42
}
A question mark (?
) may be used in place of null
.
{
"profile picture": ?
}
null
is automatically inserted between adjacent commas (.
). Note that this is done after trailing comma removal. null
is also inserted between a colon (:
) and a comma or a colon and a closing brace (}
).
{
"high scores": [100,,120,117,,,142],
"favorite band": ,
"favorite song":
}
{
(User Profile (v1.0.0\))
name: "Trinity",
nickname: "Trin",
"favorite colors": [
'#5ED7FF', (Pink)
'#F970FF', (Blue)
'#F7F7F7', (White)
],
'contact info': {
(Fake contact info)
phone_number: '+10000000000',
email_address: '[email protected]',
},
quotes: [
'"I like cake 🎂"',
"\"Hello World!\"",
'"Isn\'t this cool?"'
],
id: 1_42,
active: true, (Signed in recently?)
"profile picture": ?
}
{(User Profile (v1.0.0\))name:"Trinity",nickname:"Trin","favorite colors": ['#5ED7FF',(Pink)'#F970FF',(Blue)'#F7F7F7',(White)],'contact info':{(Fake contact info)phone_number:'+10000000000',email_address:'[email protected]',},quotes:['"I like cake 🎂"',"\"Hello World!\"",'"Isn\'t this cool?"'],id:1_42,active:true,(Signed in recently?)"profile picture":?}
{
"name": "Trinity",
"nickname": "Trin",
"favorite colors": [
"#5ED7FF",
"#F970FF",
"#F7F7F7"
],
"contact info": {
"phone_number": "+10000000000",
"email_address": "[email protected]"
},
"quotes": [
"\"I like cake 🎂\"",
"\"Hello World!\"",
"\"Isn't this cool?\""
],
"id": 142,
"active": true,
"profile picture": null
}
{"name":"Trinity","nickname":"Trin","favorite colors":["#5ED7FF","#F970FF","#F7F7F7"],"contact info":{"phone_number":"+10000000000","email_address":"[email protected]"},"quotes":["\"I like cake 🎂\"","\"Hello World!\"","\"Isn't this cool?\""],"id":142,"active":true,"profile picture":null}
- Any valid JSON should be valid JSION
- JSION should work the same on a minified form as it does in an equivalent expanded form.
- Optimizations (Combine some Regular Expressions that overlap).
- Allow semicolons to be used in place of commas.
- Expand the stringify method to support inserting comments through setting a symbol property on values.
- Expand the stringify method to use shorter space saving formats when possible.
- Improve error messages when trying to use implicit nulls between commas and not in an arrays.
- Additional number formats for positive signs, hexadecimal, octadecimal, and more.