Review and extend the documentation, and check it in CI (#5638)

* Review and extend the documentation, and check it in CI

A review of all documentation pages found factual errors, dead links,
missing cross-references, and gaps in examples. This fixes them and adds
checks so the same problems are caught automatically.

Fixes:
- wrong signatures and version histories (operator!= C++20 member,
  binary() subtype type, get<PointerType>(), JSON_NO_THREAD_LOCAL, ...)
- stale descriptions (number parsing since #5283, UBJSON table, SAX
  example that no longer compiled, tsl::ordered_map advice)
- dead internal and external links; repology.org badges (the domain is
  suspended) replaced by badges that query the registries directly
- deprecation notes link the migration guide; the guide itself fixed

Additions:
- "See also" sections, cross-references, 25 runnable examples, 12
  Mermaid diagrams, new API pages for json_pointer::operator<=> and
  byte_container_with_subtype::operator==/!=
- landing page, guides for untrusted input and performance
- "unreleased" badge after versions newer than the latest release

Checks:
- strict documentation build (broken links/anchors fail it); CI and
  the publish workflow fetch the full history the build needs
- weekly external link check, Mermaid syntax check in CI
- check_structure.py: example titles, heading levels, alt texts,
  header links, docset index coverage; its unused-example check works
  again
- all examples produce the same output on every platform

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

* Keep the customer links that could not be fixed

A dead link on the customers page is still the evidence of where the
use of the library was documented. Keep the original URLs of the entries
without a working replacement (Marne, Cisco Webex Desk Camera, Philips
Hue, CyberArk) and exclude exactly these URLs from the link check.

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

* Correct the duplicate-key recipe's claim about SAX positions

The SAX interface's key() receives no position either; only parse_error()
does. Also note that the recipe does not report the path to the repeated
key (see discussion #5085).

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

* Say the library is available as a single header and mention json_fwd.hpp

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

* Correct documentation errors found while hunting for bugs

- patch/patch_inplace: list the JSON pointer errors parse_error.106-109
  and out_of_range.402/404, and quote the actual parse_error.105 message.
- unflatten: list parse_error.106/107/108 and out_of_range.404.
- to_bson: list out_of_range.415 (binary subtype above 255) and note
  that 412 and 415 are new in 3.13.0.
- to_string: state that string_t must be convertible to std::string, also
  in the StringType requirements table.
- JSON Lines: a `while (input >> j)` loop also throws after the last value
  for concatenated JSON values; show a loop that works for both.
- BON8: a string gets 0xFF only if nothing follows it in the message; a
  string at the end of an array or object is ended by 0xFE.
- custom_string_type.hpp: add operator+=(char), which the "Always
  required" list asks for (json_pointer::to_string, flatten, unflatten,
  and diff did not compile), and an ADL int_to_string for diff and items.

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

* Cache the release headers with functools.lru_cache

Codacy (Pylint) flagged the mutable default argument that header() used
as its cache. functools.lru_cache keeps the same memoization without it.
The script's output is unchanged.

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

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-10-02 11:32:15 +02:00
committed by GitHub
parent 48ff79647f
commit 63c10a51fc
276 changed files with 5318 additions and 624 deletions

View File

@@ -26,6 +26,7 @@ header. See also the [macro overview page](../../features/macros.md).
- [**JSON_HAS_CPP_11**<br>**JSON_HAS_CPP_14**<br>**JSON_HAS_CPP_17**<br>**JSON_HAS_CPP_20**](json_has_cpp_11.md) - set supported C++ standard
- [**JSON_HAS_FILESYSTEM**<br>**JSON_HAS_EXPERIMENTAL_FILESYSTEM**](json_has_filesystem.md) - control `std::filesystem` support
- [**JSON_HAS_RANGES**](json_has_ranges.md) - control `std::ranges` support
- [**JSON_HAS_STATIC_RTTI**](json_has_static_rtti.md) - control RTTI (run time type information) support
- [**JSON_HAS_STD_FORMAT**](json_has_std_format.md) - control `std::format`/`std::formatter` support
- [**JSON_HAS_THREE_WAY_COMPARISON**](json_has_three_way_comparison.md) - control 3-way comparison support
- [**JSON_NO_AUTOMATIC_UDLS**](json_no_automatic_udls.md) - do not include the user-defined string literals (UDLs) automatically

View File

@@ -31,7 +31,7 @@ Therefore, assertions can be switched off by defining `NDEBUG`.
## Examples
??? example "Example 1: default behavior"
??? example "Example: default behavior"
The following code will trigger an assertion at runtime:
@@ -53,7 +53,7 @@ Therefore, assertions can be switched off by defining `NDEBUG`.
Assertion failed: (m_value.object->find(key) != m_value.object->end()), function operator[], file json.hpp, line 2144.
```
??? example "Example 2: user-defined behavior"
??? example "Example: user-defined behavior"
The assertion reporting can be changed by defining `JSON_ASSERT(x)` differently.

View File

@@ -70,7 +70,7 @@ The default value is `0` (disabled — existing behavior is preserved).
## Examples
??? example "Default behavior (macro not defined)"
??? example "Example: default behavior (macro not defined)"
Without the macro, single-element brace initialization wraps the value in an array:
@@ -88,7 +88,7 @@ The default value is `0` (disabled — existing behavior is preserved).
}
```
??? example "Opt-in copy semantics (macro defined to 1)"
??? example "Example: opt-in copy semantics (macro defined to 1)"
With the macro, single-element brace initialization copies/moves the value:

View File

@@ -81,7 +81,7 @@ When the macro is not defined, the library will define it to its default value.
The output shows the start/end positions of all the objects and fields in the JSON string.
??? example "Example 2: using only diagnostic positions in exceptions"
??? example "Example: using only diagnostic positions in exceptions"
```cpp
--8<-- "examples/diagnostic_positions_exception.cpp"
@@ -95,7 +95,7 @@ When the macro is not defined, the library will define it to its default value.
The output shows the exception with start/end positions only.
??? example "Example 3: using extended diagnostics with positions enabled in exceptions"
??? example "Example: using extended diagnostics with positions enabled in exceptions"
```cpp
--8<-- "examples/diagnostics_extended_positions.cpp"

View File

@@ -43,7 +43,7 @@ When the macro is not defined, the library will define it to its default value.
## Examples
??? example "Example 1: default behavior"
??? example "Example: default behavior"
```cpp
--8<-- "examples/diagnostics_standard.cpp"
@@ -57,7 +57,7 @@ When the macro is not defined, the library will define it to its default value.
This exception can be hard to debug if storing the value `#!c "12"` and accessing it is further apart.
??? example "Example 2: extended diagnostic messages"
??? example "Example: extended diagnostic messages"
```cpp
--8<-- "examples/diagnostics_extended.cpp"
@@ -71,7 +71,7 @@ When the macro is not defined, the library will define it to its default value.
Now the exception message contains a JSON Pointer `/address/housenumber` that indicates which value has the wrong type.
??? example "Example 3: using only diagnostic positions in exceptions"
??? example "Example: using only diagnostic positions in exceptions"
```cpp
--8<-- "examples/diagnostic_positions_exception.cpp"

View File

@@ -30,7 +30,7 @@ The default value is `0`.
## Examples
??? example "Example 1: Disabled behavior"
??? example "Example: Disabled behavior"
The code below forces the library **not** to create default serialization/deserialization functions `from_json` and `to_json`, meaning the code below
**does not** compile.
@@ -57,7 +57,7 @@ The default value is `0`.
}
```
??? example "Example 2: Serialize enum macro"
??? example "Example: Serialize enum macro"
The code below forces the library **not** to create default serialization/deserialization functions `from_json` and `to_json`, but uses
[`NLOHMANN_JSON_SERIALIZE_ENUM`](nlohmann_json_serialize_enum.md) to parse and serialize the enum.
@@ -90,7 +90,7 @@ The default value is `0`.
}
```
??? example "Example 3: User-defined serialization/deserialization functions"
??? example "Example: User-defined serialization/deserialization functions"
The code below forces the library **not** to create default serialization/deserialization functions `from_json` and `to_json`, but uses user-defined
functions to parse and serialize the enum.

View File

@@ -67,7 +67,7 @@ The default value is `0` (disabled — existing behavior is preserved).
## Examples
??? example "Default behavior (macro not defined)"
??? example "Example: default behavior (macro not defined)"
```cpp
#include <nlohmann/json.hpp>
@@ -83,7 +83,7 @@ The default value is `0` (disabled — existing behavior is preserved).
}
```
??? example "Conversion disabled (macro defined to 1)"
??? example "Example: conversion disabled (macro defined to 1)"
```cpp
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION 1

View File

@@ -40,6 +40,13 @@ The default value is detected based on preprocessor macros such as `#!cpp __cplu
...
```
## See also
- [JSON_HAS_FILESYSTEM / JSON_HAS_EXPERIMENTAL_FILESYSTEM](json_has_filesystem.md) - control `std::filesystem` support
- [JSON_HAS_RANGES](json_has_ranges.md) - control `std::ranges` support
- [JSON_HAS_THREE_WAY_COMPARISON](json_has_three_way_comparison.md) - control 3-way comparison support
- [JSON_HAS_STD_FORMAT](json_has_std_format.md) - control `std::format`/`std::formatter` support
## Version history
- Added in version 3.10.5.

View File

@@ -52,6 +52,11 @@ The default value is detected based on the preprocessor macros `#!cpp __cpp_lib_
...
```
## See also
- [JSON_HAS_CPP_11 / JSON_HAS_CPP_14 / JSON_HAS_CPP_17 / JSON_HAS_CPP_20 / JSON_HAS_CPP_23 /
JSON_HAS_CPP_26](json_has_cpp_11.md) - set supported C++ standard
## Version history
- Added in version 3.10.5.

View File

@@ -40,6 +40,13 @@ When the macro is not defined, the library will define it to its default value.
...
```
## See also
- [JSON_HAS_CPP_11 / JSON_HAS_CPP_14 / JSON_HAS_CPP_17 / JSON_HAS_CPP_20 / JSON_HAS_CPP_23 /
JSON_HAS_CPP_26](json_has_cpp_11.md) - set supported C++ standard
- [JSON_HAS_STD_FORMAT](json_has_std_format.md) - a similar feature-detection macro, for `std::format`/`std::formatter`
support
## Version history
- Added in version 3.11.0.

View File

@@ -25,7 +25,12 @@ When the macro is not defined, the library will define it to its default value.
...
```
## See also
- [**operator ValueType**](../basic_json/operator_ValueType.md) - get a value (implicit); on C++17, this macro
controls whether `std::any` is excluded from its candidate types
## Version history
- Added in version 3.11.3.

View File

@@ -36,6 +36,10 @@ When the macro is not defined, the library will define it to its default value.
...
```
## See also
- [`std::formatter<basic_json>`](../basic_json/std_formatter.md) - format JSON values with `std::format`
## Version history
- Added in version 3.13.0.

View File

@@ -27,6 +27,11 @@ When the macro is not defined, the library will define it to its default value.
...
```
## See also
- [**operator<=>**](../basic_json/operator_spaceship.md) - 3-way compare JSON values
- [**operator==**](../json_pointer/operator_eq.md) - compare JSON pointers for equality
## Version history
- Added in version 3.11.0.

View File

@@ -30,6 +30,11 @@ By default, `#!cpp JSON_NO_IO` is not defined.
...
```
## See also
- [**operator<<**](../operator_ltlt.md) - serialize to stream
- [**operator>>**](../operator_gtgt.md) - deserialize from stream
## Version history
- Added in version 3.10.0.

View File

@@ -43,6 +43,10 @@ Copying and comparing fall back to working without the call stack there, as they
...
```
## See also
- [FAQ: Thread safety](../../home/faq.md#thread-safety)
## Version history
- Added in version 3.12.1.
- Added in version 3.13.0.

View File

@@ -79,7 +79,7 @@ The default value is `0` (disabled — existing behavior is preserved).
## Examples
??? example "Default behavior (macro not defined)"
??? example "Example: default behavior (macro not defined)"
Without the macro, the character after a number is consumed:
@@ -99,7 +99,7 @@ The default value is `0` (disabled — existing behavior is preserved).
}
```
??? example "Opt-in precise stream position (macro defined to 1)"
??? example "Example: opt-in precise stream position (macro defined to 1)"
With the macro, the stream is positioned right after the number:

View File

@@ -24,7 +24,7 @@ By default, the macro is not defined.
## Examples
??? example
??? example "Example: switch off the version check"
The code below switches off the warning about including a different version of the library.
@@ -35,7 +35,7 @@ By default, the macro is not defined.
...
```
!!! example
??? example "Example: warning about a different library version"
The following warning will be shown in case a different version of the library was already included:
@@ -43,6 +43,11 @@ By default, the macro is not defined.
Already included a different version of the library!
```
## See also
- [NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR,
NLOHMANN_JSON_VERSION_PATCH](nlohmann_json_version_major.md) - library version information
## Version history
Added in version 3.11.0.
- Added in version 3.11.0.

View File

@@ -28,6 +28,11 @@ By default, the macro is not defined.
...
```
## See also
- [JSON_HAS_CPP_11 / JSON_HAS_CPP_14 / JSON_HAS_CPP_17 / JSON_HAS_CPP_20 / JSON_HAS_CPP_23 /
JSON_HAS_CPP_26](json_has_cpp_11.md) - set supported C++ standard
## Version history
Added in version 3.2.0.
- Added in version 3.2.0.

View File

@@ -85,7 +85,7 @@ The default value is `0` (disabled — existing behavior is preserved).
## Examples
??? example "Default behavior (macro not defined)"
??? example "Example: default behavior (macro not defined)"
Without the macro, a NUL byte silently ends parsing at that point:
@@ -101,7 +101,7 @@ The default value is `0` (disabled — existing behavior is preserved).
}
```
??? example "Opt-in strict handling (macro defined to 1)"
??? example "Example: opt-in strict handling (macro defined to 1)"
With the macro, a NUL byte is rejected like any other unexpected byte:
@@ -124,6 +124,7 @@ The default value is `0` (disabled — existing behavior is preserved).
## See also
- [:simple-cmake: JSON_StrictNulHandling](../../integration/cmake.md#json_strictnulhandling) - CMake option to control the macro
- [FAQ: NUL bytes in the input](../../home/faq.md#nul-bytes-in-the-input)
- [**parse**](../basic_json/parse.md) - deserialize from a compatible input
- [**accept**](../basic_json/accept.md) - check if the input is valid JSON

View File

@@ -26,6 +26,8 @@ When the macro is not defined, the library behaves as if it were defined to its
To prepare existing code, define `JSON_USE_GLOBAL_UDLS` to `0` and bring the string literals into scope where
needed. Refer to any of the [string literals](#see-also) for details.
See the [migration guide](../../integration/migration_guide.md#import-namespace-literals-for-udls) for how to update existing code.
!!! hint "CMake option"
The placement of user-defined string literals can also be controlled with the CMake option
@@ -39,7 +41,7 @@ When the macro is not defined, the library behaves as if it were defined to its
## Examples
??? example "Example 1: Default behavior"
??? example "Example: Default behavior"
The code below shows the default behavior using the `_json` UDL.
@@ -62,7 +64,7 @@ When the macro is not defined, the library behaves as if it were defined to its
42
```
??? example "Example 2: Namespaced UDLs"
??? example "Example: Namespaced UDLs"
The code below shows how UDLs need to be brought into scope before using `_json` when `JSON_USE_GLOBAL_UDLS` is
defined to `0`.

View File

@@ -24,6 +24,8 @@ By default, implicit conversions are enabled.
You can prepare existing code by already defining `JSON_USE_IMPLICIT_CONVERSIONS` to `0` and replace any implicit
conversions with calls to [`get`](../basic_json/get.md).
See the [migration guide](../../integration/migration_guide.md#replace-implicit-conversions) for how to update existing code.
!!! tip "Automatic migration"
The community-maintained clang-tidy check `modernize-nlohmann-json-explicit-conversions` rewrites implicit

View File

@@ -53,6 +53,8 @@ When the macro is not defined, the library will define it to its default value.
New code should not depend on it and existing code should try to remove or rewrite expressions relying on it.
See the [migration guide](../../integration/migration_guide.md#miscellaneous-functions) for how to update existing code.
!!! hint "CMake option"
Legacy comparison can also be controlled with the CMake option

View File

@@ -62,9 +62,15 @@ By default, `#!cpp JSON_USE_SIMDUTF` is not defined and the portable C++11 scala
!!! hint "Testing this configuration"
The unit tests can be built against the simdutf backend with the CMake option `JSON_TestSimdutf` (`OFF` by
default), which fetches simdutf and defines `JSON_USE_SIMDUTF` for every test target. The `ci_test_simdutf` target
runs the whole test suite in that configuration.
The unit tests can be built against the simdutf backend with the CMake option
[`JSON_TestSimdutf`](../../integration/cmake.md#json_testsimdutf) (`OFF` by default), which fetches simdutf and
defines `JSON_USE_SIMDUTF` for every test target. The `ci_test_simdutf` target runs the whole test suite in that
configuration.
## See also
- [:simple-cmake: JSON_TestSimdutf](../../integration/cmake.md#json_testsimdutf) - CMake option to build the unit
tests against the simdutf backend
## Version history

View File

@@ -149,7 +149,7 @@ void to_json(BasicJsonType& j, const B& b) {
## Examples
??? example "NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE"
??? example "Example: (1) NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE"
Consider the following complete example:

View File

@@ -83,7 +83,7 @@ See the examples below for the concrete generated code.
## Examples
??? example "Example (1): NLOHMANN_DEFINE_TYPE_INTRUSIVE"
??? example "Example: (1) NLOHMANN_DEFINE_TYPE_INTRUSIVE"
Consider the following complete example:
@@ -112,7 +112,7 @@ See the examples below for the concrete generated code.
--8<-- "examples/nlohmann_define_type_intrusive_explicit.cpp"
```
??? example "Example (2): NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT"
??? example "Example: (2) NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT"
Consider the following complete example:
@@ -142,7 +142,7 @@ See the examples below for the concrete generated code.
Note how a default-initialized `person` object is used in the `from_json` to fill missing values.
??? example "Example (3): NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE"
??? example "Example: (3) NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE"
Consider the following complete example:
```cpp hl_lines="22"

View File

@@ -82,7 +82,7 @@ See the examples below for the concrete generated code.
## Examples
??? example "Example (1): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE"
??? example "Example: (1) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE"
Consider the following complete example:
@@ -110,7 +110,7 @@ See the examples below for the concrete generated code.
--8<-- "examples/nlohmann_define_type_non_intrusive_explicit.cpp"
```
??? example "Example (2): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT"
??? example "Example: (2) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT"
Consider the following complete example:
@@ -141,7 +141,7 @@ See the examples below for the concrete generated code.
Note how a default-initialized `person` object is used in the `from_json` to fill missing values.
??? example "Example (3): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE"
??? example "Example: (3) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE"
Consider the following complete example:

View File

@@ -45,7 +45,7 @@ For further information please refer to the corresponding macros without `WITH_N
## Examples
??? example "Example (1): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES"
??? example "Example: NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES"
Consider the following complete example:
@@ -73,6 +73,21 @@ For further information please refer to the corresponding macros without `WITH_N
--8<-- "examples/nlohmann_define_type_non_intrusive_with_names_explicit.cpp"
```
## See also
- [NLOHMANN_DEFINE_TYPE_INTRUSIVE, NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT,
NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_intrusive.md) - the macros these variants add
custom JSON key names to
- [NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT,
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_non_intrusive.md) - the macros these
variants add custom JSON key names to
- [NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT,
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE,
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT,
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_derived_type.md) - similar macros for
derived types, also available with custom names
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) - overview of type conversion mechanisms
## Version history
1. Added in version 3.13.0.
- Added in version 3.13.0.

View File

@@ -44,7 +44,7 @@ inline void from_json(const BasicJsonType& j, type& e);
## Examples
??? example "Example 1: Basic usage"
??? example "Example: Basic usage"
The example shows how `NLOHMANN_JSON_SERIALIZE_ENUM` can be used to serialize/deserialize both classical enums and
C++11 enum classes:
@@ -59,7 +59,7 @@ inline void from_json(const BasicJsonType& j, type& e);
--8<-- "examples/nlohmann_json_serialize_enum.output"
```
??? example "Example 2: Multiple conversions for one enumerator"
??? example "Example: Multiple conversions for one enumerator"
The example shows how to use multiple conversions for a single enumerator. In the example, `Color::red` will always
be *serialized* to `"red"`, because the first occurring conversion. The second conversion, however, offers an

View File

@@ -47,7 +47,7 @@ inline void from_json(const BasicJsonType& j, type& e);
## Examples
??? example "Example 1: Basic usage"
??? example "Example: Basic usage"
The example shows how `NLOHMANN_JSON_SERIALIZE_ENUM_STRICT` can be used to serialize/deserialize both classical enums and
C++11 enum classes:
@@ -62,7 +62,7 @@ inline void from_json(const BasicJsonType& j, type& e);
--8<-- "examples/nlohmann_json_serialize_enum_strict.output"
```
??? example "Example 2: Multiple conversions for one enumerator"
??? example "Example: Multiple conversions for one enumerator"
The example shows how to use multiple conversions for a single enumerator. In the example, `Color::red` will always
be *serialized* to `"red"`, because the first occurring conversion. The second conversion, however, offers an
@@ -78,7 +78,7 @@ inline void from_json(const BasicJsonType& j, type& e);
--8<-- "examples/nlohmann_json_serialize_enum_strict_2.output"
```
??? example "Example 3: exceptions on invalid serialization"
??? example "Example: exceptions on invalid serialization"
The example shows how an invalid serialization causes an exception to be thrown. In the example,
Color::unknown is not defined in the mapping used to call `NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`