JSON for Modern C++: C++ JSON library
Header-only C++ library for JSON with STL-like containers.
Learn more about JSON for Modern C++
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);Enhanced conversion macros with template support, derived class conversions, std::optional support, and flexible string compatibility.
- –Enhanced conversion macros: All macros are now templated, supporting json, orderedjson, and any other basicjson specialization.
- –Derived classes can now be seamlessly converted to/from JSON using the new NLOHMANN_DEFINE_DERIVED_TYPE macros.
- –Support for std::optional: The library now supports conversions from/to std::optional types when compiled with C++17.
- –Flexible string compatibility: Functions patch, diff, and flatten now work with arbitrary string types.
Added specific parse error messages, serialization-only macros, Bazel and Swift Package Manager support, and CMake fixes.
- –Add more specific parse error message when attempting to parse empty input.
- –Add serialization-only user defined type macros (NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE).
- –Add Bazel build support. If you are using Bazel you can simply reference this repository using httparchive or gitrepository and depend on @nlohmann_json//:json.
- –Support Apple's Swift Package Manager.
- –Fix CMake header path in install with custom CMAKE_INSTALL_INCLUDEDIR.
Fixed critical regressions in value function, json_fwd.hpp header, json_pointer usage, and comparison operations.
- –Fix the value function which was broken for strings, size types, and nullptr in release 3.11.0.
- –Fix the json_fwd.hpp header to be self-contained and add it to the single-header release.
- –Fix regression that broke using json_pointer as key in associative containers.
- –Add missing constraint to deprecated JSON Pointer overloads of contains and at.
- –Fix comparison between json_pointer and strings with == and !=. These comparisons worked in 3.10.5, but were broken in 3.11.0 and 3.11.1.
Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
Create React App
Zero-configuration React scaffolding tool with preconfigured toolchain.
Swag
CLI tool that generates Swagger 2.0 API documentation from Go source code annotations.
StatsD
UDP/TCP metrics collector with pluggable backend support.
Hugo
Fast static site generator written in Go with built-in asset processing and multiple content formats.
Doom Emacs
Modular framework with lazy loading and vim keybindings.