
JSON for Modern C++
A single-header C++ library for reading, writing and manipulating JSON data.nlohmann/json
- Stars
- 50.8k
- Forks
- 7.5k
- Licence
- MIT
- Language
- C++
- Last update
- 4 days ago
- Type
- Library
What it is
nlohmann/json is a C++ library that lets programs work with JSON data using familiar C++ containers and operators, so JSON objects and arrays can be handled much like std::map and std::vector. It is distributed as a single header file, which makes it simple to add to a project. The README also mentions support for related formats such as CBOR, MessagePack and BSON, plus JSON Pointer and JSON Patch.
- Parse a JSON configuration file into a C++ object and read its values
- Build JSON responses or data structures in code using JSON literals
- Serialize C++ types to JSON and deserialize them back
- Convert data between JSON and binary formats such as CBOR or MessagePack
Great for
- C++ developers who need to read or write JSON in an application
- Teams that want a library with no dependencies and a simple header-based setup
- Projects that prioritize ease of use over raw parsing speed
- Developers who want JSON Patch or JSON Pointer support in C++
Not ideal for
- Projects that need the fastest possible JSON parsing, since the README says faster libraries exist
- Developers not working in C++, because this library is for C++ only
- Projects that must avoid a large single header file in build times, as the README does not discuss compile-time cost
How to get it
- 1
Clone and build from source
You'll need: A C++11 or later compiler
Clone the repository
git clone https://github.com/nlohmann/json.git - 2
Run it
- Add the single header json.hpp to your project include path
- Include the header in your C++ source file with #include <nlohmann/json.hpp>
- Create a json object from a literal or parse a string and print or access its values
- 3
Get the most out of it
- Use the package manager integrations listed in the README to add the library to your build system
- Consult the API reference at json.nlohmann.me for the full set of functions
- Use the examples on JSON Pointer and JSON Patch if you need to modify documents in place
- Read the binary formats section if you need CBOR, MessagePack or BSON output
Downloads
Strengths
- Single header file with no dependencies, according to the README
- Intuitive syntax that feels close to native C++ containers
- Heavily unit-tested with fuzzing via Google OSS-Fuzz and MIT licensed
Trade-offs
- The README says it is not the fastest JSON library available
- Documentation and examples are primarily hosted on an external site, so the README alone gives limited detail
- The README is truncated, so some features and setup details could not be verified here
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| json (this) | 50.8k | Library | beginner | 4 days ago | C++ developers who need to read or write JSON in an application |
| SwiftyJSON | 22.9k | Library | beginner | 3 months ago | Swift developers building iOS, macOS, tvOS or watchOS apps that read JSON from web APIs |
| gjson | 15.6k | Library | beginner | 1 months ago | Go developers who need a few fields from a JSON response without writing struct definitions |
| go | 13.9k | Library | beginner | 2.4 years ago | Go developers who parse or produce large amounts of JSON and want to test a faster option |
| cli | 24.3k | Library | intermediate | 4 days ago | Go developers writing a command line tool with subcommands and flags |
| pino | 18.3k | Library | beginner | 30 days ago | Node.js backend developers who want structured JSON logs |
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.