Navigate:
JSON for Modern C++
~$JSON0.1%

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

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

LIVE RANKINGS • 11:39 AM • STEADY
OVERALL
#268
102
DEVELOPER TOOLS
#49
21
30 DAY RANKING TREND
ovr#268
·Devel#49
STARS
49.0K
FORKS
7.3K
7D STARS
+70
7D FORKS
+8
See Repo:
Share:

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.

JSON for Modern C++

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

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

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

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.


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers