8 ms·
The Last JSON Spec
- mschuster91 9y agoI'd be happy about a JSON spec that allows for comments...
- fvdessen 9y agoYou should have a look at JSON5 http://json5.org/ http://json5.org/
- rspeer 9y agoThe fact that it has no support for Unicode at all -- neither literal nor escaped -- is just tragic.
- NoahTheDuke 9y agoHm? The spec[1] has reference to Unicode all over the place. [1]: https://json5.github.io/json5-spec/ https://json5.github.io/json5-spec/
- rspeer 9y agoIf it's supported, then they should update json5.org, which says "TODO: Unicode characters and escape sequences aren’t yet supported in this implementation."
- jrimbault 9y agoThe reason why comments aren't allowed anymore in the spec: https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaGSr https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaG... And a conversation about it: https://news.ycombinator.com/item?id=3912149 https://news.ycombinator.com/item?id=3912149
- coldtea 9y ago>The reason why comments aren't allowed anymore in the spec Is BS.
- kroltan 9y agoExactly. { "__directive__": "phpstyle_stringly_typed", "boolean": "true" }
- BillinghamJ 9y agoNope, because that is still completely valid JSON. Sure it's kind of a shitty choice of structure, but every JSON parser on the planet will be able to read it successfully. If you choose to layer some extra logic/rules on top of the actual parsing, that's fine - that would be entirely within the intended purpose of JSON. Comments are FAR more likely to be used more like "preprocessor directives" to influence actual parsing rules, changing the syntax. Whereas your example conforms perfectly to the syntax, leaving parsing as-is and ensuring the logic is handled at a higher level.
- xg15 9y agoBut if you're already changing the syntax, why do you worry about JSON interop at all? Just invent your own language. If you do worry about JSON interop, then JSON-with-parsing-directives-disguised-as-comments would be valid JSON as well - just treat the directives as comments and ignore them. The resulting tree would probably not reflect the data that the author ment to encode (because you ignored the directives) - but neither would the tree from the example above.
- mseebach 9y agoIt seems a bit like a baby-and-bathwater situation, honestly. It seems feasible to put in the standard something like that comments must be stripped out in the first pass and may never influence the interpretation of the non-commented JSON. A parser-implementation might choose to ignore that, but then it wouldn't be a standards-compliant JSON parser, in the same way it wouldn't be if it brazenly ignored any of the other sections of the standard.
- ChrisSD 9y agoPersonally I've never found that to be an issue when using JSON as a data interchange format. The only place I'd like to have comments is in configuration files and in that case there are less verbose formats that do allow for comments.
- viraptor 9y agoI never really understood json for config files. It's not that readable. It's great for data exchange and relatively human-readable representation, but if you ask people to actually write and maintain it, why not yaml / toml / ...?
- vidarh 9y agoYAML suffers from significant whitespace, which makes me for one refuse to ever consider it. Personally I consider YAML less human writable than JSON for that reason. TOML is tolerable, but all my preferred languages already have JSON parsers I'm familiar with, but while they may have TOML parsers, I'd have to go looking for onne.
- jghn 9y agoHOCON[1] is a pretty reasonable compromise, IMO. I've really only seen it used by Scala and Scala-y Java, which makes sense considering its lineage. [1] https://en.wikipedia.org/wiki/HOCON https://en.wikipedia.org/wiki/HOCON
- krapp 9y agoJSON is readable enough. The format is simple - no inline functions, no circular references, just maps or arrays of key-value pairs. This makes it well suited for describing what a config file should, which is an initial application state, without much needless abstraction. Config isn't meant to be code, and config files shouldn't be updated often, so a config file format doesn't need a great deal of expressiveness. Dealing with quoting keys and commas in JSON isn't more or less of a hassle than dealing with significant whitespace or whatever pecadillos those other formats have. Although personally I really like Lua tables for config because they have an even simpler structure than JSON and you can add comments. I have to resist the tempation to turn Lua config files into applications, though.
- tlocke 9y agoWhat about Zish? It's like JSON but with comments, a timestamp type, a decimal type and a bytes type: https://github.com/tlocke/zish https://github.com/tlocke/zish (as the author, I'm biased)
- billpg 9y agoMy unsolicited comments. I really want to see a good JSON-done-right out there and your spec is maybe 90% there. I'd rather only /* */ comments were allowed. By allowing //, you've now got two varieties of white-space the parser needs to be aware of. Because of this, I can't take multiple lines of ZISH and join them together into a single line. (Something both JSON and XML can do.) What is a "line"? CR, LF, CRLF, LFCR, FF, VT, U+0085, U+2028, U+2029? Am I required to treat ZISH files as "binary"? Could I convert all of those end-of-line bytes into my OS's preferred form without losing data? The notation of ending a line with a \ also prevents joining multiple lines into a single line. Maybe formalize "string"+"string" as an explicit string joining notation? (Or if not +, some other character to notate string concatenation.) Given you have the decimal type, is float necessary? Values with a "e" are still expressed with decimal digits. Is there a limit to numeric types? What if my ZISH file contained a several hundred 9s in a row? Sets seems unnecessary given you already have lists. You can take a list and treat it as a set after parsing with no loss of data. I very much like the addition of timestamps and binary without needing a string. This is my big pet peeve of JSON. Your examples include uses of null and true, but your spec doesn't define those values. (Or false for that matter.) The description of map doesn't specify if the order of keys is significant. Is {"a":"b", "c":"d"} the same as {"c":"d", "a":"b"} ?
- tlocke 9y agoThis is quite brilliant, thanks billpg. I'm also amazingly grateful that someone's taken an interest in Zish :-) These questions will all require some thought to properly understand and respond to, with no-doubt some changes to the spec. So I've opened an issue and put the comment at: https://github.com/tlocke/zish/issues/2 https://github.com/tlocke/zish/issues/2
- Flenser 9y ago
- SiVal 9y agoI'd rather have trailing commas, so every line can have the same format. Other people choose JSON for their config file format, and I don't have a say in it. I just have to do extra editing each time I reorder the lines or add a new one, because too bad. And I have to manually edit JSON when I'm writing code to handle other people's JSON APIs to test my code. I'll probably never not have to manually edit JSON, so JSON's insistence that using the same format for your final line as for all the others won't ever be allowed will remain a never ending, unnecessary nuisance in the spirit of JavaScript itself: the "too bad, too late now" school of design. Except that in this case, even JavaScript corrected that particular nuisance and allows trailing commas.
- dtech 9y agoIf you want a JSON-ish config format, I'd recommend to check out HOCON [1], basically a superset of JSON that fixes all he things that make it annoying for config files. [1] https://github.com/lightbend/config https://github.com/lightbend/config
- eptcyka 9y agoIf we're proposing supersets of json, why wouldn't one just use yaml?
- zimbatm 9y agoAll because IE6 wasn't supporting trailing commas at the time when JSON was written. Shortly after that we discovered that it was a bad idea to eval() JSON so the whole reason for browser compatibility became moot. But who knows, maybe that is what was needed at the time to make JSON popular.
- IgorPartola 9y agoIf the config is in the form of: { "file": "/etc/foo", "daemon": true } Couldn't you add comments like so, all within the existing spec? { "file": "/etc/foo", "_daemon_comment": "default is false", "daemon": true }
- olavk 9y agoGoes to show that there is no perfect format for all use cases. The lack of comments is a good thing for interoperability in machine-to-machine communication. But it a bad thing for hand-written configuration files.
- dtech 9y agoWhy are no comments good for interoperability? Numerous formats can contain comments and I've never seen someone having a problem parsing them out, especially since they usually cannot be nested and/or allow you to skip until the next newline. I personally dislike it the most when you want to provide a commented example of your data format, vanilla JSON won't allow you to do that.
- drderidder 9y ago{ "_comments": [ "Hello." ] }
- Mizza 9y agoYou probably don't want comments sent on the wire, but if you like JSON as a config format but want it to me more human-tolerant, you can try HJSON: https://hjson.org/ https://hjson.org/ I like it more than any other config format, really.
- philsnow 9y agothis has many of the misfeatures of yaml, like ambiguity of values. { a: 5 } is that "5" or 5? with JSON it's unambiguous.
- rurban 9y agoFine that they didn't another insecurity as in the latest updates. JSON is still the only secure transportation protocol if you don't use the RFC 9159 simplification, http://search.cpan.org/~mlehmann/JSON-XS-3.02/XS.pm#SECURITY_CONSIDERATIONS http://search.cpan.org/~mlehmann/JSON-XS-3.02/XS.pm#SECURITY...
- viraptor 9y agoWhat do you mean by "only secure transportation protocol"? There's nothing inherently insecure in XML, yaml, asn1, bson, cbor, msgpack, out whatever other popular format. Implementations may fail, but that's a different problem.
- masklinn 9y ago* YAML is pretty much inherently insecure, custom tags are part of the YAML spec and are interpreted by default by most implementations, the YAML 1.2 spec only recommends defaulting to the "core" schemaor a lesser one and (AFAIK) at no point even suggests disabling explicit tags. * XML is most definitely inherently insecure if you don't disable or strictly limit standard features (entity definition/expansion, external entity definition, DTD retrieval). I don't know about the others, I do know that ASN.1 has a long and storied history of vulnerable implementations (and it's unclear whether there's ever been a secure one) which tells me that even if the format is not inherently insecure, in practical terms it is.
- viraptor 9y agoBoth cases make good, secure implementations harder. They don't make the protocol itself insecure since you can make implementations that avoid these issues. There's nothing in the protocol itself that forces you into a situation of "choose between valid or secure".
- masklinn 9y ago> Both cases make good, secure implementations harder. You literally can't secure XML without refusing to enable (or implement) standard features.
- 1wd 9y ago"we still lack a decent high-quality JSON Schema language" Yes. Why?
- signalsmith 9y agoThe JSON Schema spec was abandoned by its original authors, and was picked up by a series of other people with varying levels of standards experience (myself included). Personally, I had some promising support from my then-employer (including an IETF connection), but then it kind of petered out, and I was buried under other stuff and had to pass it on. The team who picked it up since them seem pretty on-the-ball as far as I can see, so I would still recommend it as a useful project to contribute to. It is supported by some tools - last I heard, Visual Studio could use JSON Schema for autocomplete and validation, as well as a couple of databases. I used to get a few million NPM downloads a month on my validator, so someone's clearly using it.
- beaconstudios 9y agoThere's also the excellent dtsgenerator which converts json schemas to typescript type definitions.
- alexatkeplar 9y agoAs far as I know, Snowplow is one of the largest active users of JSON Schema, and we maintain one of the larger repositories of JSON Schemas on the internet, https://github.com/snowplow/iglu-central https://github.com/snowplow/iglu-central After something of a hiatus, we are re-starting active work on our schema registry technology (https://github.com/snowplow/iglu https://github.com/snowplow/iglu). We'd love to be involved in new design work on the JSON Schema spec. How do we get the old (or new!) band back together?
- hyperpallium 9y agoUnfortunately, power complexes. When more power is needed than json has (e.g. a schema language), there is xml and the xml ecosystem (e.g. xs), with all the tools, features and standards you could possibly want... actually, more. Thus, it is the complexity of xml that keeps json simple. It is the same principle as keeping flies off the dinner table by dumping a pile of manure outside the front door.
- geraldbauer 9y agoFYI: I've put together an Awesome JSON (What's Next?) page [1] collecting all JSON next flavors incl. JSON5, HJSON, HanSON, SON, CSON, USON, JSONX/JSON11 and many more. Yes, comments (in JSON 1.1), please :-) Cheers. [1] https://github.com/jsonii/awesome-json-next https://github.com/jsonii/awesome-json-next
- geraldbauer 9y agoFYI: For the Microservices Austria meetup I've put together a talk titled "Meet Jason - The Universal Data Exchange Format - What's Next?", find the notes (transcript) @ https://github.com/geraldb/talks/blob/master/jsonnext.md https://github.com/geraldb/talks/blob/master/jsonnext.md Yes, comments (in JSON 1.1), please :-). Cheers.
- jancsika 9y agoIt's a lot of fun reading the spec and realizing you can hold the entire thing in your head, and probably also make a decent implementation in the language of your choice. It would be neat to take that as a model and try to compose a new type of browser where each functional module must consist of a spec that is similarly succinct and easy to implement, perhaps with the exception of ECMAscript.
- bcg1 9y ago> "On the other hand, we still lack a decent high-quality JSON Schema language." This turns data integration with JSON into a total nightmare. And to make matters worse, Swagger is a total shitshow. Combine the different flavors of JSON schema with OpenAPI/Swagger and you have are left with a regression from SOAP/XML that approaches the same complexity with with fewer features and no standards. Even mf COBOL has a standard schema definition for data. For new projects I'm still cranking out XSD definitions and doing transformations to JSON if I have to. Even if they come out with a decent schema format I would probably skip it and jump straight to gRPC, Thrift, or some other IDL and just continue to treat JSON as an "also supports".