cJSON
Ultralightweight JSON parser in ANSI C
A tiny JSON parser for C programs that fits in a single source file and header. Copy two files into your project and start reading or writing JSON with no build system required, targeting even old C89 compilers.
cJSON is a tiny JSON parser written in C. JSON is a text format for storing and transmitting data, commonly used between web services, configuration files, and programs that need to share information. cJSON exists to give C programs a simple way to read and write that format without a heavy dependency or complicated setup.
The entire library is just one C source file and one header file. To use it, you can copy those two files directly into your project and start calling the functions. No build system required, though the project also supports CMake, Meson, and the vcpkg package manager if you prefer a more structured approach. Because it targets ANSI C (specifically the C89 standard), it runs on a very wide range of platforms and older compilers, which is why embedded and systems developers reach for it.
The README explains two main operations: parsing JSON into a tree of C data structures, and printing a tree back out to a JSON string. You navigate the parsed tree by checking each node's type (number, string, array, object, boolean, or null) and reading its value. The library gives you functions to create, modify, and delete nodes, so you can build JSON from scratch as well as consume it.
The README also lists several caveats worth knowing. cJSON is not thread-safe by default. It does not handle characters with a value of zero inside strings. Floating-point numbers may not round-trip exactly due to how C represents them. Deeply nested arrays and objects can cause a stack overflow because the library uses recursion. These are practical trade-offs in a library that prioritizes simplicity and small size over completeness.
Where it fits
- Add JSON config file parsing to an embedded or firmware project by copying two files into your C codebase.
- Build a lightweight HTTP API client in C that reads JSON responses from a web service without a heavy library dependency.
- Serialize C data structures to JSON strings for logging or inter-process communication on constrained hardware.