JSON for Modern C++: C++ JSON library
Header-only C++ library for JSON with STL-like containers.
Learn more about json
JSON for Modern C++ is a header-only library that enables C++ programs to work with JSON data structures. The library implements JSON parsing and serialization with support for multiple binary formats including BSON, CBOR, MessagePack, and UBJSON. It offers STL-compatible containers and iterators, allowing JSON objects and arrays to be manipulated using familiar C++ patterns. The library supports JSON Pointer, JSON Patch, and JSON Merge Patch operations as defined in relevant RFCs, and includes automatic type conversion between JSON and C++ data structures.

Header-only design
The library is implemented entirely in headers, eliminating the need for separate compilation or linking. This simplifies integration into C++ projects and reduces build complexity.
Multiple binary format support
Beyond standard JSON, the library can serialize and deserialize BSON, CBOR, MessagePack, UBJSON, and BJData formats. This allows interoperability with systems using different data serialization standards.
STL container integration
JSON objects and arrays implement STL-compatible interfaces, enabling iteration, indexing, and manipulation using standard C++ algorithms and patterns. The library also supports automatic conversion between JSON and arbitrary C++ types through specializable conversion functions.
#include <nlohmann/json.hpp>
#include <iostream>
using json = nlohmann::json;
json user_data = json::parse(R"({"name": "Alice", "age": 30, "active": true})");
std::cout << user_data["name"] << std::endl;
int age = user_data["age"];
bool is_active = user_data.value("active", false);Backward-compatible release adding diagnostic byte positions, std::optional support (C++17), and templated conversion macros for ordered_json.
- –Enable JSON_DIAGNOSTIC_POSITIONS macro to include byte positions in exceptions and query parse locations for debugging.
- –Use NLOHMANN_DEFINE_DERIVED_TYPE_* macros to serialize derived classes or std::optional types when compiling with C++17.
Backward-compatible bug-fix release addressing CMake policy warnings, compiler compatibility issues, and memory leaks; no breaking changes or new requirements.
- –Update CMake files to accept policies up to 3.14, fixing deprecation warnings and custom install path issues.
- –Fix memory leak when exceptions are thrown in adl_serializer and resolve GCC compatibility by replacing INT_MIN/MAX with std::numeric_limits.
Backward-compatible bug-fix release restoring 3.10.5 behavior for `value()`, `json_pointer` comparisons, and forward-declaration header; deprecates comparing JSON Pointers directly with strings.
- –Update code comparing `json_pointer` with strings to explicitly convert strings to `json_pointer` before using `==` or `!=` to avoid deprecated operators.
- –Verify `value()` calls with strings, size types, or `nullptr` work correctly if upgrading from broken 3.11.0/3.11.1; `json_fwd.hpp` is now self-contained.
Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
redoc
React component rendering OpenAPI specifications as interactive HTML documentation.
googletest
xUnit-based C++ testing framework with integrated mocking.
tradingview
Custom datafeed integration for Tradingview charting library.
nvm
nvm is a per-user, per-shell version manager for Node.js that allows switching between multiple installed Node versions from the command line. It works on any POSIX-compliant shell across Unix, macOS, and Windows WSL environments.
posthog
Event tracking, analytics, and experimentation platform.