Find your next open-source project

Search by name, purpose, or keyword — or paste a GitHub repository URL

nlohmann/json

Developer Tools

A header-only C++11 JSON library with STL-like syntax, serialization, binary formats, and JSON Patch support.

50,845
7,517
C++
MIT
13 years old

Overview

nlohmann/json is a single-header C++ library that makes JSON behave like a first-class data type. Instead of calling a separate parser object, you write json j;, assign nested values with [], and serialize with <<. The design goal is an intuitive syntax matching how JSON works in languages such as Python, built with modern C++ operators (design goals).

The library targets RFC 8259 conformance and offers more than parsing: STL-like container access, conversion to and from standard containers and custom types, JSON Pointer (RFC 6901), JSON Patch (RFC 6902), JSON Merge Patch (RFC 7396), and binary encodings BSON, CBOR, MessagePack, UBJSON, BJData, and BON8 (binary formats). It is aimed at C++ projects that want an ergonomic JSON API rather than a minimal C-style parser.

Quick start

Integration is header-only: include single_include/nlohmann/json.hpp or download a release package, then add the include and using nlohmann::json (integration). A minimal program reading a file looks like this:

#include <fstream>
#include <nlohmann/json.hpp>
using nlohmann::json;

int main() {
    std::ifstream f("example.json");
    json data = json::parse(f);
    return 0;
}

For CMake projects, locate the package and link the interface target:

find_package(nlohmann_json 3.12.0 REQUIRED)
target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)

To build and run the test suite: mkdir build && cd build && cmake .. -DJSON_BuildTests=On && cmake --build . && ctest --output-on-failure. The test run downloads JSON test data from an external repository, so offline builds need extra configuration (execute unit tests).

Usage constraints

  • Requires C++11 or later. The project lists tested compilers from GCC 4.8 and Clang 3.4 through recent MSVC, Intel, and CUDA compilers; other versions may work but are not guaranteed (supported compilers).
  • Input is UTF-8 by default; std::u16string and std::u32string can be parsed as UTF-16/UTF-32 but only in memory, not when reading files or input containers. Latin-1 and ISO 8859-1 are not supported.
  • Comments and trailing commas are errors by default. parse accepts an ignore_trailing_commas option, but comments remain unsupported without an explicit setting (comments).
  • Object key insertion order is not preserved by default; nlohmann::ordered_json is available if ordering matters (order of object keys).
  • Implicit conversions from json to C++ types are discouraged by the maintainer; they can be disabled with JSON_USE_IMPLICIT_CONVERSIONS=0 or the CMake option JSON_ImplicitConversions=OFF.
  • The library is MIT licensed (license).

HotRepo's take

On the C++ daily list for 2026-11-06, the project recorded its best rank of fifth that day and gained 8 stars. It has roughly 50.8k stars and 7.5k forks overall. Discussion on Hacker News has been split: one commenter praised the ergonomic API but worried about compile time and preferred rapidjson (comment); another reported using it on an ESP32 in single-core mode where performance was sufficient (reply). Those tradeoffs are the practical ones to weigh: convenient, feature-rich API versus heavier compilation and lower raw throughput than specialized parsers. The 2019 thread also noted that including json_fwd.hpp in headers can limit compile-time cost (comment).

Written by AI from the project's README, updated . The project's own docs are the source of truth.

Hacker News

JSON for Modern C++
▲ 189 · 121 comments · September 29, 2019
JSON for Modern C++ version 3.10.0
▲ 134 · 101 comments · August 18, 2021