Navigate:
~$JSON0.1%

JSON for Modern C++: C++ JSON library

Header-only C++ library for JSON with STL-like containers.

LIVE RANKINGS • 06:52 AM • STEADY
TOP 100TOP 100TOP 100TOP 100TOP 100TOP 100TOP 100TOP 100TOP 100TOP 100TOP 100TOP 100
OVERALL
#89
35
DEVELOPER TOOLS
#16
5
30 DAY RANKING TREND
ovr#89
·Devel#16
STARS
48.5K
FORKS
7.3K
DOWNLOADS
350.4K
7D STARS
+45
7D FORKS
-1
See Repo:
Share:

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.

json

1

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.

2

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.

3

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);

vv3.12.0

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.
vv3.11.3

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.
vv3.11.2

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.


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers