The Last JSON Spec
tbray.org
tbray.org
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.
But who knows, maybe that is what was needed at the time to make JSON popular.
{
"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
}Because Douglas Crockford didn't want people abusing comments in JSON by turning them into parsing directives, JSON doesn't allow using comments at all, even correctly, so everyone is left abusing JSON itself with workarounds that are objectively worse than just having comments.
https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaG...
And a conversation about it:
Is BS.
{
"__directive__": "phpstyle_stringly_typed",
"boolean": "true"
}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.
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.
First, I didn't say it can't happen. Just that it's a BS concern to be worried about in the spec.
For one, this thing he is worried can already happen without comments -- just needs a second pass after the parser (or of the parser).
Second, this can already happen without comments and a single pass parsing -- just needs out of band parsing instructions.
Those needing special parsing pragmas can get them anyway.
And the same problem didn't emerge in lots of other formats that allow comments.
https://github.com/tlocke/zish
(as the author, I'm biased)
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"} ?
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.
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.
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.
JSON doesnt care as long as it's valid, and there are parsers for every language and environment.
If the parsers do something different, that's an implementation issue, which inevitably affects all formats. This affects json as well: http://seriot.ch/parsing_json.php
I had to diff on-wire JSON payloads to find a discrepancy, and boy was it a pain, whereas having those trailing commas would have reduced the diff to a quite direct and obvious pointer to the faulty change.
I like it more than any other config format, really.
{
a: 5
}
is that "5" or 5? with JSON it's unambiguous.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.
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".
Yes. Why?
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.
After something of a hiatus, we are re-starting active work on our schema registry technology (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?
It is the same principle as keeping flies off the dinner table by dumping a pile of manure outside the front door.
type Book = {
title: string;
author: Author;
isbn?: string;
}
//etc
It's easier to read and write by humans than JSON-Schema, a large amount of programmers are already familiar with the syntax, and it's pretty self-explanatory to most programmers who are not.Sure, it doesn't have constraints like "maximum string length" and "must start with a capital" etc, but I'd wager that those don't really belong in a schema language anyway. The structure and the types is what matters. Once you got that covered, doing some validation on the content of the values is easy. And you can use a Real Programming Language for it, instead of something half assed.
How can you validate a JSON string to see if it matches a TypeScript declaration?
* Section 1.2 has been updated to reflect the removal of a JSON specification from ECMA-262, to make ECMA-404 a normative reference, and to explain the particular meaning of "normative".
* Section 1.3 has been updated to reflect errata filed against RFC 7159, not RFC 4627.
* Section 8.1 was changed to require the use of UTF-8 when transmitted over a network.
* Section 12 has been updated to increase the precision of the description of the security risk that follows from using the ECMAScript "eval()" function.
* Section 14.1 has been updated to include ECMA-404 as a normative reference.
* Section 14.2 has been updated to remove ECMA-404, update the version of ECMA-262, and refresh the errata list.
So
* RFC 8259 requires UTF-8 encoding (for network transmissions)
* ECMA-404 has been upgraded from Informative (14.2) to Normative (14.1)
* Wording has been improved or fixed in some cases
Restricting to UTF-8 and disallowing the previous allowed UT-16 and UTF-32 BOM's (which my JSON library is the only one which did support that), is the most prominent change, yes.
What is troubling to me is that they now prefer relaxed RFC 7159 over strict RFC 4627. The RFC 7159 relaxed mode was a troubled update which harms security, and it should not be turned on by default.
And whilst they support now the insecure relaxed variant, they didn't clarify the still problematic points in the spec. MUST disallow duplicate keys, or MAY? It's not specified, or specified twice contradicting itself. Same for broken UTF-8 encodings. Error or warn or silence?
It's still much better than the YAML spec though. Minor nitpicks.
* 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.
Also, it has had almost 40 years of additions, so it is now a large spec.
Too many people have reinvented ASN.1 badly. Protocol Buffers, I'm looking at you!
You literally can't secure XML without refusing to enable (or implement) standard features.
BTW The latest 2 JSON specs also are now insecure by default, in its relaxed RFC 7159 mode, allowing values such as objects, arrays, strings, numbers, "null", "true", and "false".
Wait: default msgpack is also insecure, as you can trivially add packets to the front or end, overriding it. It also accepts cutoff or corrupted packets. Only my patched msgpack version was better, but only for prepending packets, not for added packets after. https://github.com/msgpack/msgpack/pull/114
Ummm, canonical s-expressions[0] and ASN.1's various encoding rules[1] beg to differ.
The one thing JSON has that canonical s-expressions don't is maps/hash tables/dicts, but after working with both for quite awhile I've come to the conclusion that maps in the core transport language are actually a mistake.
[0] http://people.csail.mit.edu/rivest/Sexp.txt
[1] https://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One#O...
Only in the exact same sense that JSON allows insecure object deserialisation. Yes, if you process a JSON object or S-expression, your processor can do all sorts of insecure things. But a non-buggy S-expression parser can't do anything wrong with (foo bar "baz"), just as a non-buggy JSON parser can't do anything wrong with ["foo", "bar", "baz"].
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.