Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why are you hand writing JSON? Pass a JavaScript object, which doesn't have these limitations, to the JSON serialerizer.

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.



Writing, or at least editing, JSON by hand seems unavoidable if you develop on Node, as modules' "manifests" are JSON files.

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.


I believe you should do something like this:

  json.stringify({unquoted:'Some value', trailing_comma:true,})
instead of hand-writting JSON data in tests.


I have implemented a javascript eval into my text editor. When I select text, and call the command, it passes it off to a node.JS engine and replaces the selection with the return result. In this way I can write a JSON.stringify([anyvalid javascript],null, [indentation]); and instantly get perfect JSON. This is much less troublesome than trying to make a new slightly incompatible format.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: