News for hackers. Stuff that matters.
Re:Parsing JSON is a Minefield by dagenix on Monday April 23, 2018 @01:46AM (#16900799)
So if JSON parsers can't agree on what JSON actually is, that isn't a problem?
Re:Parsing JSON is a Minefield by arghwhat on Monday April 23, 2018 @05:03AM (#16901740)
JSON 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".

Re:Parsing JSON is a Minefield by jacobparker on Monday April 23, 2018 @08:27AM (#16902749)
> As the robustness principle goes [...]

"The Harmful Consequences of the Robustness Principle" https://tools.ietf.org/html/draft-thomson-postel-was-wrong-0...

Re:Parsing JSON is a Minefield by meuk on Saturday April 28, 2018 @08:05AM (#16947270)
I 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.

Re:Parsing JSON is a Minefield by craftyguy on Tuesday April 24, 2018 @10:36AM (#16912904)
The 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?
Re:Parsing JSON is a Minefield by benzoate on Monday April 23, 2018 @03:11AM (#16901122)
I consider it more like behaviour outside of the spec is undefined, and some parsers have bugs.
Re:Parsing JSON is a Minefield by dagenix on Monday April 23, 2018 @11:23AM (#16904201)
A good spec should define all those corner cases. With Json, it's possible for two bug free libraries to take the same input and produce a different output.
Re:Parsing JSON is a Minefield by arghwhat on Tuesday April 24, 2018 @05:47AM (#16911210)
Only if the input is invalid JSON.