JSON5; Designed for Humans
Posted by Dion Almaer 11 months ago on json open_source
JSON is a great serialization format that can be somewhat readable for folks… especially JavaScript-y folks. There has been a long debate on the fact that it is primed for machine to machine conversations and conversions.
Some of us also like to use JSON in other ways, as configuration for example. Open up that package.json and you may wish that there was a comment or two. Quotes everywhere? Really?
This is where JSON5 by Aseem Kishore comes into play. It adds features that many would love to see (but don’t get past the “nope! doesn’t belong!” police):
- Object keys don’t need to be quoted if they’re valid identifiers. Yes, even reserved keywords are valid unquoted keys in ES5.
- Strings can be single-quoted.
- Strings can be split across multiple lines; just prefix each newline with a backslash.
- Objects and arrays can have trailing commas.
- Both inline (single-line) and block (multi-line) comments are allowed.
- Numbers can be hexadecimal (base 16), and they can also begin with a leading decimal (e.g. .5).
If you have ever been That Guy who had eval’d his config file as JavaScript vs. JSON. Or even jumped over to something like YAML, come back…. the water is getting warm here (even if Doug thinks that it is due to people peeing in his pool!)
Aside: I still giggle like a school girl when I think of the Samsung “designed for humans” line. Check out their launch event for a reason why so many prefer an Apple launch event :/