DaveGamble/cJSON logo

DaveGamble/cJSON

Free

Ultralightweight JSON parser in ANSI C

FreeFree tier
Type
Open Source

About DaveGamble/cJSON

cJSON is an ultralightweight JSON parser written in ANSI C (C89) that consists of only one C file and one header file. It aims to be the simplest possible parser to get the job done, providing functionality for parsing JSON strings into a C data structure and printing C data structures back to JSON. It supports basic JSON value types including strings, numbers, booleans, null, arrays, and objects. The library is designed for portability across many platforms and compilers, and is available under the MIT license. cJSON is widely used in embedded systems and other C projects that require minimal dependencies and a small footprint.

Key Features

Single-file implementation (cJSON.c and cJSON.h) for easy integration
Written in ANSI C (C89) for maximum portability
Supports parsing JSON strings into C data structures
Supports printing C data structures back to JSON strings
Handles basic types: strings, numbers, booleans, null
Handles arrays and objects with nesting
MIT license allows free use in open-source and proprietary projects
Multiple build options: CMake, Makefile, Meson, Vcpkg

Pros & Cons

Pros
  • Extremely lightweight and simple to integrate (single file pair)
  • Portable across many platforms due to ANSI C compliance
  • Free and open source (MIT license) with no strings attached
  • Long-standing mature project with many contributors and stars
  • Small memory footprint suitable for resource-constrained environments
Cons
  • No built-in validation for duplicate object members (behavior is undefined)
  • Not thread-safe by default; requires external synchronization
  • Limited error handling and reporting (dumb parser design philosophy)
  • No support for streaming parsing; entire JSON must be in memory
  • Not suitable for extremely large JSON documents due to recursion on deep nesting

Best For

Embedded systems that need lightweight JSON parsingC applications requiring minimal-dependency JSON handlingProjects that need to serialize/deserialize configuration files in JSON formatIoT devices with constrained resourcesEducational purposes to understand JSON parsing in C

FAQ

What is cJSON?
cJSON is an ultralightweight JSON parser written in ANSI C. It is a single-file library that allows parsing JSON into C data structures and printing C data structures as JSON.
How do I include cJSON in my project?
You can simply copy cJSON.h and cJSON.c into your project source and start using it. Alternatively, you can use CMake, Makefile, Meson, or Vcpkg for a full build system.
What license does cJSON use?
cJSON is distributed under the MIT License, Copyright (c) 2009-2017 Dave Gamble and cJSON contributors. It is free to use, modify, and distribute.
Is cJSON thread-safe?
cJSON is not thread-safe by default. The user must provide external synchronization if using the library across multiple threads.
Does cJSON support deep nesting of arrays and objects?
cJSON supports nesting, but has practical limits due to recursion. Deeply nested structures may cause stack overflows on some platforms. The library includes a recursion limit check in newer versions.