Parse JSON in ANSI C

c, json

Solution

Try jsmn lib, I love that it can parse any json file with only two malloc's.

jsmn is a minimalistic library for parsing JSON data format. It can be easily used in small projects or can be integrated into embedded systems.

jsmn is a good choice, because:

- it is compatible with C89 compiler version

- it uses no dynamic memory allocation

- it has the smallest possible overhead

- it needs only one pass to parse JSON data

- it has no dependencies, even libc

- it is distributed under MIT license, so you can use it in your proprietary projects

Problem

I'd like to read JSON-encoded data into C structs. The structure of the json data is known in advance, relatively flat and mimicked by some C struct typedefs. An array at the third level or so contains an extremely lengthy list of JSON objects which have to be processed one at a time. The code is intended to run on a very constrained system so the library should not dynamically allocate memory. I know there is Crockford's List of JSON libraries, but I'm not quite sure which one is the best fit for the stated problem.

Original source

Related problems