4 ms·
There's already a few 'allow comments in JSON' projects around (http://commentjson.readthedocs.org/en/latest/ http://commentjson.readthedocs.org/en/latest/ for
by onion2k 12y ago
There's already a few 'allow comments in JSON' projects around (http://commentjson.readthedocs.org/en/latest/ http://commentjson.readthedocs.org/en/latest/ for example), but you've gone a bit further and that's great.
However... I think Crockford gets it right: https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaGSr https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaG... He suggests allowing ordinary JS comments in JSON files, and pushing it through something that strips the comments (eg jsmin) before parsing it. The only reason to have comments in the file is if you're hand-editing it. If that's the case then you could add anything you want so long as it's removed before the parser see it.
I'd go further, and just say don't write JSON files by hand. You can hack together a form to make even complex objects with JSON2 and jQuery in about 20 minutes.