Skip to content

cJSON

A small, single-file JSON parser and writer library for C programs.

Stars
13.1k
Forks
3.6k
Licence
MIT
Language
C
Last update
2 months ago
Type
Library

What it is

cJSON is a C library for reading and writing JSON data. The README says it is a single C source file plus a single header, so it can be copied straight into a project. It is written in ANSI C (C89) to work across many platforms and compilers.

  • Parse a JSON configuration file inside a C program
  • Build a JSON document in memory and print it out as text
  • Read and modify fields of an existing JSON object or array
  • Add cJSON to a C project via CMake, Meson, or vcpkg

Great for

  • C developers who need to read or write JSON in their programs
  • Embedded or small projects where a tiny dependency is preferred
  • Projects that want to copy in one .c and one .h file instead of managing a build dependency
  • Developers who want a simple, dumb-by-design parser with little abstraction

Not ideal for

  • Developers working in languages other than C, since this is a C library (the README does not cover other language bindings)
  • Users who need a ready-made end-user application; cJSON is code to include in your own program
  • Projects needing the strongest guarantees on edge cases, since the README has a Caveats section covering limits such as thread safety, floating point and deep nesting that need checking
Step-by-step guide: how to use cJSONInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Clone and build from source

    You'll need: A C compiler · CMake 3.5 or higher (recommended build method)

    Build with CMake (out-of-tree, from the README)

    mkdir build && cd build && cmake .. && make

    Install system-wide (from the README)

    make install
  2. 2

    Run it

    • Copy cJSON.h and cJSON.c into your project, or build and install with CMake
    • Include the header with #include <cjson/cJSON.h> if installed via CMake or the Makefile
    • Parse JSON text or create cJSON items using the library's functions
    • Print the result or free the items when finished
  3. 3

    Get the most out of it

    • Enable the test suite and sanitizers with -DENABLE_CJSON_TEST=On and -DENABLE_SANITIZERS=On when developing
    • Use the optional cJSON_Utils module with -DENABLE_CJSON_UTILS=On
    • Use cJSON_SetNumberValue rather than writing to valueint directly, as the README marks direct writes as deprecated
    • Read the Caveats section (zero characters, encoding, thread safety, duplicate object members) before relying on it in production

Downloads

Strengths

  • Very small: the README describes it as one C file and one header file
  • Portable: written in ANSI C (C89) to support many platforms and compilers
  • Multiple integration options, including CMake, a Makefile, Meson, and vcpkg

Trade-offs

  • The README marks the Makefile build as deprecated, with CMake recommended
  • Has caveats documented in the README (e.g., thread safety, floating point, deep nesting) that users must understand
  • Requires C programming knowledge to use

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.