JSON isn't the friendliest to write. Keys need to be quoted, objects and
arrays can't have trailing commas, and comments aren't allowed — even though
none of these are the case with regular JavaScript today.

That was fine when JSON's goal was to be a great data format, but JSON's usage
has expanded beyond machines. JSON is now used for writing configs,
manifests, even tests — all by humans.

There are other formats that are human-friendlier, like YAML, but changing
from JSON to a completely different format is undesirable in many cases.
JSON5’s aim is to remain close to JSON and JavaScript.

This JavaScript implementation of JSON5 simply provides a JSON5 object just
like the native ES5 JSON object.

To use from Node:

npm install json5

var JSON5 =require('json5');

To use in the browser (adds the JSON5 object to the global namespace):

<script src="json5.js"></script>

Then in both cases, you can simply replace native JSON calls with JSON5:

var obj = JSON5.parse('{unquoted:"key",trailing:"comma",}');

var str = JSON5.stringify(obj);

JSON5.parse supports all of the JSON5 features listed above (TODO: except
Unicode), as well as the native reviver argument.

JSON5.stringify mainly avoids quoting keys where possible, but we hope to
keep expanding it in the future (e.g. to also output trailing commas).
It supports the native replacer and space arguments,
as well. (TODO: Any implemented toJSON methods aren't used today.)

Douglas Crockford of course designed and built
JSON, but his state machine diagrams on the JSON website,
as cheesy as it may sound, gave me motivation and confidence that building a
new parser to implement these ideas this was within my reach!
This code is also modeled directly off of Doug's open-source json_parse.js
parser. I'm super grateful for that clean and well-documented code.

Max Nanasy has been an early and prolific
supporter, contributing multiple patches and ideas. Thanks Max!