3 ms·
Good point about the numbers! Double::parseDouble accepts a superset of JSON numbers, so the risk here is that something which is not a valid JSON number will b
by twic 10y ago
Good point about the numbers! Double::parseDouble accepts a superset of JSON numbers, so the risk here is that something which is not a valid JSON number will be accepted. That could be tackled by building up the string, checking it against a regular expression for JSON numbers, and then parsing it. It wouldn't add any states to the parser, and would take two lines of code.
I would suggest that in a JSON parser, attempting to recover from parse errors, or supporting frequent errors, would be a mistake. JSON, unlike CSV, has a rigorous definition, and we wouldn't be doing the world any favours by tolerating deviations from it.
I'm not sure what the security issues with long strings would be. Text gets accumulated in a StringBuilder, which will handle strings up to 2 GB and then throw an exception. I don't think there's any way to get into an incorrect state.
Your other points relate to design decisions, and ones where i'm quite happy with the options i chose.