explaingit

davegamble/cjson

12,711CAudience · developerComplexity · 2/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((cjson))
    What It Does
      Parse JSON to C tree
      Build JSON from C
      Single file library
    Tech Stack
      C89 standard
      CMake optional
      Meson optional
    Use Cases
      Embedded firmware
      Config file parsing
      API response parsing
    Audience
      C developers
      Embedded engineers
      Systems programmers
    Caveats
      Not thread-safe
      No null chars in strings
      Recursion depth limit
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add JSON config file parsing to an embedded or firmware project by copying two files into your C codebase.

USE CASE 2

Build a lightweight HTTP API client in C that reads JSON responses from a web service without a heavy library dependency.

USE CASE 3

Serialize C data structures to JSON strings for logging or inter-process communication on constrained hardware.

Tech stack

CCMakeMeson

Getting it running

Difficulty · easy Time to first run · 5min

Not thread-safe by default and uses recursion that can overflow the stack on deeply nested JSON structures.

No license information is described in the explanation, check the repository before using the code in your project.

In plain English

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.

Copy-paste prompts

Prompt 1
I'm writing firmware in C and need to parse a JSON config file. Show me how to add cJSON to my project, parse an object, and read a string field from it.
Prompt 2
How do I use cJSON to build a JSON object from scratch in C and print it as a formatted string?
Prompt 3
Walk me through safely iterating over a JSON array with cJSON and extracting integer values from each element.
Prompt 4
What are the thread-safety and stack overflow risks I need to know before using cJSON in a multi-threaded embedded application?
Prompt 5
How do I use cJSON with CMake so it is fetched and linked automatically when I build my project?
Open on GitHub → Explain another repo

← davegamble on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.