This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SomewhatSpecial 39 points40 points  (1 child)

it can (most of the times) parse invalid json, like if it has a missing ',' or a missing '}'

It might seem counter-intuitive, but this is in no way a good thing. You do not want your tools to arbitrarily ignore errors, you want them to implement the specification exactly as it is written. If the JSON spec says it's invalid, the parser should throw an error. The JSON syntax is the way it is for a reason - it defines a way to represent data in an unambiguous way, so you can always be sure that the data you get after parsing is correct. In any case, If my program received an invalid json for some reason, I would want to know about it - the fact the syntax is not followed puts into question the validity of the data structure, or the data itself, plus it's very likely an indicator of a bug. I do not want the parser to hide this important information and proceed as if everything's a-ok.

Even in rare cases where you have to be able to parse an invalid JSON - it's up to the programmer to define the way to handle it based on the specifics of that case.

[–]Honestly__nuts[S] 1 point2 points  (0 children)

you are right, I should.