JSON parsing in ANSI C

I would like to read JSON encoded data in C structures. The structure of json data is known in advance, relatively flat and imitated by some C struct typedefs. An array at level three or so contains an extremely long list of JSON objects that need to be processed one at a time.

The code is designed to work in a very limited system, so the library should not dynamically allocate memory.

I know that there is a Crockford List of JSON Libraries , but I'm not quite sure which one is best for the indicated problem.

+16
json c
May 20 '12 at 15:05
source share
2 answers

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

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

JSNM is a good choice because:

  • it is compatible with the C89 compiler version
  • it does not use dynamic memory allocation
  • it has the lowest possible overhead
  • JSON data analysis requires only one pass
  • it has no dependencies, even libc
  • it is licensed under MIT, so you can use it in your own projects
+19
May 20 '12 at 17:52
source share

Try with json-c is one of the most common and is open source and also works on Windows (Win32).

JSON-C implements a reference counting object model that allows you to easily build JSON objects in C, output them as formatted JSON strings, and parse JSON strings formatted in the C representation of JSON objects.

+3
May 20 '12 at 15:10
source share



All Articles