3 ms·
Comments are nice when your JSON is at-rest (e.g. in a file) but more often than not it's in-flight and my code is probably not adding comments when building a
by thom_nic 12y ago
Comments are nice when your JSON is at-rest (e.g. in a file) but more often than not it's in-flight and my code is probably not adding comments when building a message.
Come to think of it, what would an API look like that writes HJSON? Not pretty, probably.
I like the unquoted strings and trailing comma, but the rest I don't think is unnecessary. I'd be happy with the standard ECMAScript map literal format.
- captainmuon 12y agoSure, but messages in-fligt not what this is for. This is only for writing "JSON" manually. I don't think there are many use cases where you have to generate comments programmatically. I haven't looked at HJSON in detail, but JSON5 which is very similar has exactly the same writing API as JSON. Namely just `stringify`, which produces plain compliant JSON. HJSON additionally seems round-trip safe, which means if you start with comments, they are preserved, which is nice for config files. I don't think anybody sane considers sending out non-standard HJSON over the wire where plain JSON is expected.