Repolode
nlohmann

nlohmann/json

A header-only C++11 library that lets C++ code parse, build, manipulate and serialize JSON with STL-like syntax.

Stars
50,790
Forks
7,511
Open issues
19
Last commit
5 hours ago

What is it?

JSON for Modern C++ is a C++ library for working with JSON values as if they were native data types. A JSON value is represented by a single class, basic_json (aliased as nlohmann::json), which can be built from literals, STL containers, or user-defined types, and accessed with operators and familiar container methods.

The whole library is distributed as a single header file, so it can be added to a project without a separate build step or dependencies. It supports JSON Pointer (RFC 6901), JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7396), including diff generation, and it can convert to and from several binary formats such as BSON, CBOR, MessagePack, UBJSON, BJData and BON8.

User-defined types can be mapped to JSON through to_json and from_json functions or through helper macros that generate them. The project publishes documentation and an API reference, and lists CMake and common package manager integration.

Key features

  • 01Single-header integration with no dependencies, written in C++11.
  • 02Intuitive, STL-like access and assignment syntax for JSON values.
  • 03Parsing from strings, streams and iterator ranges, plus serialization with indentation.
  • 04JSON Pointer, JSON Patch, and JSON Merge Patch support, including diff generation.
  • 05Conversion to and from binary formats such as CBOR, MessagePack, BSON and UBJSON.
  • 06Macros and conversion functions for mapping custom C++ types to JSON.

Use cases

  • Reading configuration files or API payloads in a C++ application.
  • Building JSON responses or messages from C++ data structures.
  • Computing and applying JSON patches between document versions.
  • Serializing C++ structs to JSON or binary formats for storage or transport.

Quick start

  1. 1

    Add the single header file json.hpp from the repository to your project, or install it through a package manager

  2. 2

    Include the header in your C++ code with #include <nlohmann/json.hpp> and start using the json type

Things to know

  • The README states that faster JSON libraries exist, so this one prioritizes ease of use over speed.

Topics

FAQ

What is json?
A header-only C++11 library that lets C++ code parse, build, manipulate and serialize JSON with STL-like syntax. JSON for Modern C++ is a C++ library for working with JSON values as if they were native data types. A JSON value is represented by a single class, basic_json (aliased as nlohmann::json), which can be built from literals, STL containers, or user-defined types, and accessed with operators and familiar container methods.
Is json free to use? What license does it have?
json is open source under the MIT license. Check the license terms before using it in commercial products.
Is json still maintained?
Actively maintained. The last commit to json was on Oct 21, 2026.
What can I use json for?
Reading configuration files or API payloads in a C++ application. Building JSON responses or messages from C++ data structures. Computing and applying JSON patches between document versions. Serializing C++ structs to JSON or binary formats for storage or transport.
How do I install json?
Add the single header file json.hpp from the repository to your project, or install it through a package manager Include the header in your C++ code with #include <nlohmann/json.hpp> and start using the json type
Where can I get json?
The source code and installation instructions are on GitHub: https://github.com/nlohmann/json

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects