JSON parser
Languages and libraries
json parser library
SHOW HN2012
How HN took it
1 positive, 5 neutral or asking, 0 mixed, 15 critical, out of 21 comments about the project. Thread score -0.55.
Execution: 1 for, 10 againstDesign: 0 for, 5 against
The thread, comment by comment
Each row is a top-level comment and its replies, in HN's order. Select a cell to open that comment on HN.
positive neutral or mixed critical about another commenter or something else the maker
What HN said
What people liked
Lightweight and easy to use, comparable to other C JSON parsers
From 2 comments
What are you doing with json.h:121 in _json_value::&operator[](const char* index) when your key doesn't exist? Still, very nice. Comparable to jsonxx which i've been using up…
mappu on HNI like using Jansson: http://www.digip.org/jansson/
roschdal on HN
Objections
Integer and float parsing uses strtol/strtod in an unsafe way
From 2 comments
``` const json_char *cur_line_begin, *i; ... top->u.dbl = strtod (i, (json_char **) &i); top->u.integer = strtol (i, (json_char **) &i, 10); ``` Ick
schlecht on HN``` case JSON_INTEGER: obj = QOBJECT(qint_from_int(strtoll(token_get_value(token), NULL, 10))); ``` Why is it so hard to parse integer from string correctly?
adobriyan on HN
Portability concerns with hex lookup tables and character set assumptions
From 2 comments
Is JSON guaranteed to be ASCII? To clarify: Any "lookup table" that maps hex values to assumed character values is a portability red flag. When using them, it's polite to add…
feralchimp on HNNeither the execution nor source character set (of C) is guaranteed to be ASCII though. This makes the general parsing as well as lines like "if (c >= 'A' && c <= 'F')"…
pantaloons on HN
No tests provided
From 2 comments
Where are the tests?
robocop on HNOh, thanks. I was starting to feel weird because nobody was saying anything about the lack of tests. HN may or may not work as a code review platform, but I don't think I would…
reidrac on HN
Requests
Handle input lengths over 2^31 and unsigned length types
From 1 comment
What happens when the input length is longer than 2^31? You used an "int" for the length (also, why ever use a signed value for length?) --- even on LP64, that counter wraps at…
tptacek on HN
Handle UTF-16 surrogate pairs and truncated \u escapes
From 1 comment
\u is utf16 so you should be able to append two characters to get something in the extended unicode set outside ucs16. You dont seem to handle this; not sure how many parsers do.…
justincormack on HN
Questions
Why not use isdigit or enums
From 3 comments
Any reason you roll your own numeric() instead of using isdigit()? It's in C89.
avar on HNWhy are you doing "#define numeric(b) ((b) >= '0' && (b) <= '9')" instead of say isdigit(3) ?
schlecht on HNwhy are the flag values not enums (and why is 4 missing?)? is using a lookup table for decoding hex really faster than the (minimal) logic (what if it causes cache misses)? do…
andrewcooke on HN
How missing keys are handled in operator[]
From 1 comment
What are you doing with json.h:121 in _json_value::&operator[](const char* index) when your key doesn't exist? Still, very nice. Comparable to jsonxx which i've been using up…
mappu on HN
Alternatives named
YAJL
From 2 comments
What's wrong with YAJL?
haberman on HNNothing, YAJL got a lot of things very right. We use it in our C daemons for a bunch of things. Not having to unpack the whole JSON into memory is pretty handy.
lflux on HN
Jansson
From 2 comments
I like using Jansson: http://www.digip.org/jansson/
roschdal on HN+1 for Jansson here too. Lightweight and works really well.
scumola on HN
cJSON
From 1 comment
I've used cJSON (http://sourceforge.net/projects/cjson/) in the past, which worked very well for what I needed (simple 1 file JSON parser for config files). Maybe I'll give this…
tcas on HN
jsmn
From 1 comment
Here's another minimalist alternative: https://bitbucket.org/zserge/jsmn/wiki/Home I've used it and think it's pretty neat. One of these days I'll get around to releasing the…
m_eiman on HN
ultrajson
From 1 comment
Another alternative, https://github.com/esnme/ultrajson "Ultra fast JSON decoder and encoder written in C with Python bindings" From the people that built the Battlefield 3 web…
mape on HN