mcpp index

nlohmann.json

import

JSON for Modern C++, exposed as C++23 module nlohmann.json

import nlohmann.json;
mcpp add nlohmann.json@3.12.0

Usage

From this repository's own test project — built and run by CI, not written for the website.

// Behavioral test: build → dump → parse round-trip + the ordered_json variant.
import std;
import nlohmann.json;
using namespace nlohmann::literals;

int main() {
    nlohmann::json j = { {"answer", 42}, {"list", {1, 2, 3}} };
    nlohmann::json parsed = nlohmann::json::parse(j.dump());
    auto lit = R"({"k":true})"_json;
    nlohmann::ordered_json oj; oj["z"] = 1; oj["a"] = 2;
    bool ok = parsed["answer"] == 42 && parsed["list"][2] == 3
              && lit["k"] == true && oj.dump() == R"({"z":1,"a":2})";
    return ok ? 0 : 1;
}

tests/examples/nlohmann.json/tests/roundtrip.cpp · project tests/examples/nlohmann.json

Build

modules
nlohmann.json
targets
nlohmann_json (lib)
language
c++23
import std
no
include dirs
*/single_include

Sources (1)

  • mcpp_generated/nlohmann.json.cppm

Generated files

  • mcpp_generated/nlohmann.json.cppm

Versions

VersionPlatforms Mirrorssha256
3.12.0 latest LinuxWindowsmacOS CN GLOBAL 4b92eb0c06d1…