Live data from Hacker News

Show HN: Very low footprint JSON parser in portable ANSI C

github.com

41–50 of 58 posts

Re: Show HN: Very low footprint JSON parser in portable ANSI C

#41

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 comments to explicitly call out the code page dependency and argue (from a spec or RFC, say) why that assumption is okay.

http://www.ietf.org/rfc/rfc4627 specifies that the encoding must be Unicode: "JSON text SHALL be encoded in Unicode. The default encoding is UTF-8."

Neither 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')" non-portable.

Re: Show HN: Very low footprint JSON parser in portable ANSI C

#42

Earlier quoted context omitted.

http://www.ietf.org/rfc/rfc4627 specifies that the encoding must be Unicode: "JSON text SHALL be encoded in Unicode. The default encoding is UTF-8."

Neither 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')" non-portable.

Non-portable to different character sets, not platforms. One could argue that the argument to json_parse is a UTF-8 string.

Re: Show HN: Very low footprint JSON parser in portable ANSI C

#46

There definitely is a lack of good JSON parsers for C. We wrote our own in QEMU. The relevant code is: http://git.qemu.org/?p=qemu.git;a=blob;f=json-lexer.c;h=3cd3... http://git.qemu.org/?p=qemu.git;a=blob;f=json-parser.c;h=849... Among other things, this supports streaming, is fairly fast, and has gotten a fair bit of scrutiny against malicious input. The lexer is a hand written state machine which seems like someth…

What's wrong with YAJL?

Nothing is wrong with yajl it is awesome! I have used the lua module for yajl for some time with no hiccups.

Re: Show HN: Very low footprint JSON parser in portable ANSI C

#48
post #44

Where are the tests?

Oh, 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 use myself a 3rd party software that doesn't provide tests.

Re: Show HN: Very low footprint JSON parser in portable ANSI C

#50

This Show HN makes me think there needs to be a site for more formalized code reviews of open software. Ideally with some great game mechanics to make sure engagement is high and thing are getting reviewed well.

As a younger programmer with great ambitions, some sort of code review site would be awesome!
Post reply on HN