JSON for Modern C++ treats JSON as a native C++ type with parse, serialize, and STL-like access. Ships as a single header with optional CMake and package-manager integration.
Overview
JSON for Modern C++ is a C++11 library that lets applications work with JSON values as first-class objects in code. Values can be built from literals, files, streams, or iterator ranges, then inspected, modified, and serialized back to text or streams.
The API mirrors familiar container patterns: typed checks, element access, iteration, and comparison operators. It supports RFC JSON Pointer and JSON Patch for addressing and differencing documents, plus JSON Merge Patch for alternate update semantics. Custom C++ types can plug in through documented conversion hooks.
Beyond UTF-8 JSON text, the library reads and writes several binary encodings, including BSON, CBOR, MessagePack, UBJSON, and related formats noted in the project materials. Parsing can use a DOM model or a SAX-style interface for custom handling without building a full tree.
Integration is intentionally lightweight: the core is a single header file with no mandatory dependencies, and the project documents CMake, package managers, and pkg-config paths. UTF-8 is assumed for string serialization, with configurable error handling when dumping non-UTF-8 content.
Key features
- Single-header C++11 integration
- Parse and serialize JSON from strings or streams
- STL-like access and container conversions
- JSON Pointer, Patch, and Merge Patch
- Binary format import and export
- SAX-style parsing interface
- Custom type serialization hooks
- JSON literal and user-defined literal support
Use cases
- Parsing configuration and API payloads in C++
- Building and editing JSON documents in memory
- Applying patch operations between JSON versions
- Interchanging data via CBOR or MessagePack