Skip to content

JavaScript-ish Object Notation - A superset of JSON with comments, single quote strings, unquoted property names, trailing commas, and other quality of life features

License

Notifications You must be signed in to change notification settings

SteveBeeblebrox/JSION

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

98 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

JSION GitHub GitHub last commit GitHub issues GitHub code size in bytes GitHub contributors GitHub Repo stars

JavaScript-ish Object Notation - A superset of JSON with comments, single quote strings, unquoted property names, trailing commas, and other quality of life features

Files

  • 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...

Syntax

JSION adds the following features to standard JSON.

Comments

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? *)
}

Unquoted Property Names

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"
}

Trailing Commas

Just like in JavaScript, trailing commas after a value are ignored in objects and arrays.

{
    "activity": [
        "2021",
        "2022",
        "2024",
    ],
}

Single Quoted Strings

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?"'
    ]
}

Numeric Separators

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
}

Additional Numeric Literals

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
    ]
}

Shorthand Null

One or more question marks may be used in place of null.

{
    "profile picture": ???
}

Implicit Null Items

Missing values in objects and arrays are interpreted as null. Note that trailing comma removal in arrays happens after!

{
    "alt text": ,
    "icons": [,"admin",,,"flower",,]
}

Complete Example

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]}

Motivation & Goals

  • 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)

Planned Features

  • 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

About

JavaScript-ish Object Notation - A superset of JSON with comments, single quote strings, unquoted property names, trailing commas, and other quality of life features

Topics

Resources

License

Stars

Watchers

Forks