31 ms·
> I can implement a full, strict, compliant JSON parser in an afternoon, maybe even less time. Can you really? Doesn’t look like anyone else can: http://seriot
by glouwbug 5y ago
> I can implement a full, strict, compliant JSON parser in an afternoon, maybe even less time.
Can you really? Doesn’t look like anyone else can:
http://seriot.ch/parsing_json.php http://seriot.ch/parsing_json.php
- theamk 5y agoIf you actually look at this, the results are not nearly as bad as title suggests. There are are many parsers which perfectly parse every valid JSON document (like every Perl, Python and PHP parser and many others). They got non-perfect score because they accepted some JSON which standard says they should not have -- like a NaN value or a trailing comma. While using such parsers can potentially cause problems -- perhaps because your data generator has a bug, and your not-strict-enough parser ignores this bug -- this happens very rarely in practice.
- jchw 5y agoMaybe? :) I haven’t tried. I did do this one actually in an afternoon: https://github.com/pangbox/rugburn/blob/master/src/json.c https://github.com/pangbox/rugburn/blob/master/src/json.c ... but I will say that it is intentionally very limited in its API due to its intended use case and desired footprint. (And because it’s designed to compile with OpenWatcom 2 with no libc for only Win32, but those particular constraints are not very interesting for this.) I would imagine if I did try, I would have a fighting chance at making something properly strict. But I admittedly don’t know how to handle recursion in a stackless manner. Edit: specifically for C, it would be hard to do it properly unless I had access to an implementation of Clinger and Steele & White. Go would be easier since it has better floating point algorithms with strconv, but relying on C strtod/etc. is probably a bad idea due to variability. That having been said, maybe you could do Clinger in the same afternoon; I’d be worried about edge cases, but simply put, I haven’t tried.
- bjoli 5y agoI am not a programmer, and I have written one over the course of a week. It passed all the tests in the particular JSON test suite mentioned in the article except one, by design. It allowed bad unicode in parts of the document, because that was the data it was being fed. I am not even a programmer by profession. Anyone that can write a recursive descent parser can write a JSON parser.