This idea stemmed from long-running frustration every time I hand-wrote JSON (particularly common for Node/npm packages and test cases). After stewing on it for over a year, I bit the bullet today and made it a reality.
Feedback greatly welcome!
This idea stemmed from long-running frustration every time I hand-wrote JSON (particularly common for Node/npm packages and test cases). After stewing on it for over a year, I bit the bullet today and made it a reality.
Feedback greatly welcome!
1) to be language agnostic. Following ES5's syntax directions is fine for ES5 focused development, possibly not for others.
2) to be final - i.e. there is no version number. If you want to extend or build something else, I am fairly certain Douglas would prefer that you call it something else. See http://inkdroid.org/journal/2012/04/30/lessons-of-json/ at 5:30 in the video.
Don't take these points as criticisms, I too would like to be able to use single quotes and trailing commas and everything else here. I think though that in order to work with JSON as a static spec, an alternative approach could be to have your project be a layer like HAML, SASS or CoffeeScript. Each of those tools compiles or transforms to conforming input for their target specs rather than replacing them.
I'm aware that JSON is final — it's my hope that a new format that's easier to write (whether this or something else) picks up steam — but thanks for the feedback on the name! I consciously used a different file extension (.json5) to avoid conflicts; hopefully that's a good start.
I already use (and love) CoffeeScript, but my motivation for building this was to have tools use it natively, so that sibling files in a different format wouldn't have to be maintained alongside the needed JSON.
The support for evaling in the various engines doesn't matter because you should not be evaling JSON strings for security purposes.
The serialization format is strict for a reason: look at where less strict HTML parsing has gotten us.
I also love to make tests data-driven where possible. JSON is the natural format for data on Node, and again, test cases are usually written by hand (before code exists to generate or validate them).
I'm not sure I understand your point about eval'ing. This parser doesn't use eval(), and it works in every modern browser.
Finally, I'm not advocating for arbitrary looseness. These additions conform directly to ES5's additions.
json.stringify({unquoted:'Some value', trailing_comma:true,})
instead of hand-writting JSON data in tests.I think this fixes most of the problems of using it in hand-written situations. Just the lack of comments in JSON makes it inappropriate for configuration files and tests.
But this shouldn't be called JSON. JSON is strict and doesn't include comments because it's designed for interoperability between different systems. Just because it's been abused to be used for configuration files doesn't mean it needs fixing. One just needs to use the right tool for the job. Your project might be the right tool but then it's not JSON.
If I had a penny for every time a trailing comma in a json config file bit me, I would have...many pennies!
I am indifferent about single vs double quotes. The backslash newline escape seems 'messy'.
Not a fan of keys not being quoted. That stikes me as wrongish for some reason that I can't put my finger on.