4 ms·
Not really... just add a "comment" key and then ignore it when processing.
by angersock 13y ago
Not really... just add a "comment" key and then ignore it when processing.
- swift 13y agoThat's pretty ugly in practice. A better solution is to use YAML for things like configuration files. It's more pleasant for a human than JSON would be even if it supported comments, and there are nice parsing libraries available for every popular language.
- eliben 13y agoThat's an ugly workaround, not a solution. It helps breed half-baked "solutions" like the "pipe through jsmin" Crockford himself suggests. Ultimately, it makes JSON unsuitable for configuration files (there are other reasons for that, to be fair, like over-verboseness)
- oneeyedpigeon 13y agoNot necessarily. If you're naming your keys nicely, and using an easily-understandable structure, for simple config files, you shouldn't really need comments.
- eliben 13y ago"simple config files" implies an optimist. Good for you, sir.
- duaneb 13y agoYes, that solution OBVIOUSLY removes the need to spend an extra minute adding comments to the spec. Also, I hope, trailing commas and binary types.
- jonny_eh 13y agoIt takes a minute to add anything to a spec. It increases the cost of implementing the spec a lot more than a minute though.
- angersock 13y agoShoving binary into JSON is rather silly--base 64 encode it, or consider using a binary format better suited to your need. As for adding comments to the spec--again, the idea is to prevent shadow information showing up that isn't obvious to a conformant parser. If you give people the ability to smuggle data in comments, that's exactly what they'll do. At least this way people know that what they're doing isn't "to spec" and that their sneaky parsers are not following the rules.
- duaneb 13y agoI mean, JSON itself is rather silly in that it's a horrible serialization language. Its main boon is its C-style syntax, which is why it's so readable to all of us who read similar syntaxes all day. Even just a syntactical change noting which strings were base64 encoded would be nice.