Files
json/docs/mkdocs/docs/index.md
T
Niels Lohmann 330fbead59 Document clang-tidy exclusions, drop unneeded ones, and clean up doc examples (#5909)
* Document clang-tidy exclusions and drop unneeded ones

Re-enable every excluded check in a run of clang-tidy 22 over all tests
and remove the seven that never fire (cert-err58-cpp,
clang-analyzer-webkit.NoUncountedMemberChecker,
cppcoreguidelines-virtual-class-destructor, google-readability-function-size,
hicpp-function-size, hicpp-no-assembler, readability-function-size).

Document the reason for every remaining exclusion at the top of the file.

Exclude in advance the checks that only exist in clang-tidy 23 and are
noise here (bugprone-signed-bitwise, *-explicit-constructor,
readability-trailing-comma, modernize-use-string-view), plus
modernize-use-integer-sign-comparison, which needs C++20 std::cmp_less
and flags deliberate casts.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Fix clang-tidy findings in documentation examples and replace redundant aliases

Apply clang-tidy fixes to the documentation examples:
- performance-avoid-endl: std::endl -> '\n'
- readability-qualified-auto: auto -> auto* / const auto*
- performance-for-range-copy: copy -> const reference
- google-readability-casting: C-style cast -> static_cast

Replace redundant aliases (readability-redundant-qualified-alias) such as
"using json = nlohmann::json;" with "using nlohmann::json;" in the
documentation, README, examples, tests, and benchmarks. Aliases at class
scope and aliases of other types (with_base_class_t etc.) are kept.

No changes to the library or its public API. All changed examples were
compiled and run; their output matches the stored .output files (except
max_size and meta, which depend on the platform and compiler).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Format doc examples with the pinned astyle

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 12:07:51 +01:00

4.0 KiB

JSON for Modern C++

JSON for Modern C++

JSON for Modern C++ is a header-only C++11 library that turns JSON into a first-class C++ data type, using the operator magic of modern C++ so that creating, reading, and modifying JSON values feels as natural as it does in languages like Python. The whole library is available as a single header, json.hpp, with no dependencies, no subproject, and no complex build system to set up; a companion header, json_fwd.hpp, provides forward declarations to keep compile times down, <nlohmann/json_literals.hpp> holds the user-defined string literals on their own, and <nlohmann/json_view.hpp> adds zero-copy views and editable documents. See header-only integration for details. It is heavily unit-tested with 100% code coverage, checked with Valgrind and the Clang Sanitizers for memory leaks, and continuously fuzz-tested by Google OSS-Fuzz.

Quick start

Add the single header to your project and use the library like this:

#include <iostream>
#include <nlohmann/json.hpp>

using nlohmann::json;

int main()
{
    // parse a JSON string
    json j = json::parse(R"({"happy": true, "pi": 3.141})");

    // access and modify values
    j["name"] = "Niels";
    j["list"] = {1, 0, 2};

    // read a value into a C++ variable and use it
    double pi = j["pi"].get<double>();
    std::cout << "2 * pi = " << 2 * pi << '\n';

    // serialize with an indent of 4 spaces
    std::cout << j.dump(4) << '\n';
}

Get the library by copying the single header json.hpp from the releases page into a directory nlohmann on your include path, or by installing it with a package manager:

brew install nlohmann-json    # Homebrew
vcpkg install nlohmann-json   # vcpkg
find_package(nlohmann_json 3.12.0 REQUIRED)
target_link_libraries(myproject PRIVATE nlohmann_json::nlohmann_json)

See Integration for CMake in detail, all supported package managers (Conan, Meson, Bazel, Conda, and more), and pkg-config.

Explore the documentation

  • :octicons-rocket-24:{ .lg .middle } Features


    Creating, parsing, accessing, and serializing JSON values, JSON Pointer/Patch, binary formats, zero-copy views, and more.

    :octicons-arrow-right-24: Features

  • :octicons-package-24:{ .lg .middle } Integration


    Add the library to your project via a single header, CMake, a package manager, or pkg-config.

    :octicons-arrow-right-24: Integration

  • :octicons-book-24:{ .lg .middle } API documentation


    The complete reference for basic_json and its member functions, types, and related classes, as well as for json_document and json_view.

    :octicons-arrow-right-24: API documentation

  • :octicons-question-24:{ .lg .middle } FAQ


    Answers to common questions and known surprises when using the library.

    :octicons-arrow-right-24: FAQ

  • :octicons-tag-24:{ .lg .middle } Releases


    What changed in each release, with links to the relevant documentation.

    :octicons-arrow-right-24: Releases

  • :octicons-people-24:{ .lg .middle } Community


    The ecosystem, contribution guidelines, governance, and quality assurance around the project.

    :octicons-arrow-right-24: Community

!!! info "Unreleased changes"

This documentation is built from the `develop` branch and may describe changes that are not part of a release
yet. Their version numbers are followed by an <span class="unreleased-version">unreleased</span> badge; see
[Releases](home/releases/index.md) for what shipped in each version.

The library is licensed under the MIT License. The source code, issue tracker, and discussions are on GitHub.