Sunday, May 08, 2022

JSON5 Data Interchange Format: "JSON for humans"

JSON is simplified subset of JavaScript data syntax.
Adding a few more JS features to JSON would help usability.

The JSON5 Data Interchange Format (json5.org)

"The JSON5 Data Interchange Format (JSON5) is a superset of JSON that aims to alleviate some of the limitations of JSON by expanding its syntax to include some productions from ECMAScript 5.1.

Similar to JSON, JSON5 can represent four primitive types (strings, numbers, Booleans, and null) and two structured types (objects and arrays)."



example:
{
  // comments
  unquoted: 'and you can quote me on that',
  singleQuotes: 'I can use "double quotes" here',
  lineBreaks: "Look, Mom! \
No \\n's!",
  hexadecimal: 0xdecaf,
  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
  positiveSign: +1,
  trailingComma: 'in objects', andIn: ['arrays',],
  "backwardsCompatible": "with JSON",
}

this may be one of most downloaded on NPM? Weekly Downloads: 55,801,906







there are also official "readonly" versions in DotNet (C#) and GoLang (go) JSON5 @github







Currently, this library is about 20x SLOWER than using Jackson.

Rust


ANTLR parser grammar for JSON5




JSON5 is an extension to the popular JSON file format that aims to be easier to write and maintain by hand (e.g. for config files). It is not intended to be used for machine-to-machine communication. (Keep using JSON or other file formats for that. 🙂)

here is WHY: it is SLOW

JSON5#parse x 327 ops/sec ±6.58% (31 runs sampled)
JSON#parse x 5,940 ops/sec ±5.23% (76 runs sampled)
JSON5#stringify x 1,270 ops/sec ±1.38% (85 runs sampled)
JSON#stringify x 13,748 ops/sec ±2.06% (84 runs sampled)

No comments: