5 ms·
So if JSON parsers can't agree on what JSON actually is, that isn't a problem?
by dagenix 9y ago
So if JSON parsers can't agree on what JSON actually is, that isn't a problem?
- benzoate 9y agoI consider it more like behaviour outside of the spec is undefined, and some parsers have bugs.
- arghwhat 9y agoJSON parsers all agree what JSON actually is (except for the brown colored fields in the compat matrix, which are actual JSON compat bugs). JSON parsers may also permit various additional variations which are very explicitly not JSON. This means that they may accept a handcrafted, technically invalid JSON document. However, a JSON encoder may never generate a document containing such "extensions", as this would not be JSON. This concept of having parsers accept more than necessary follows best practices of robustness. As the robustness principle goes: "Be conservative in what you do, be liberal in what you accept from others".
- jacobparker 9y ago> As the robustness principle goes [...] "The Harmful Consequences of the Robustness Principle" https://tools.ietf.org/html/draft-thomson-postel-was-wrong-03 https://tools.ietf.org/html/draft-thomson-postel-was-wrong-0...
- craftyguy 9y agoThe author advocates adding previously invalid extensions to the spec as they come up, as an alternate way to handle 'robustness'. How would this not rapidly lead to a bloated, buggy, unmaintainable spec?
- meuk 9y agoI want to upvote this so many more times than I'm able to. The principle is even more harmful, because it sounds so logical. If many JSON parser accept your JSON object which is not valid JSON, any new parser that doesn't accept it will be booed as a faulty parser. If your input is not according to spec, throw an error. The sender is wrong. They deserve to know it and need to fix their output.