This commit is contained in:
nlohmann
2026-10-03 05:43:12 +00:00
parent 2aaa1d24ef
commit a410b4f40f
741 changed files with 8115 additions and 2252 deletions
File diff suppressed because one or more lines are too long
+1
View File
@@ -29,6 +29,7 @@ Some aspects of the library can be configured by defining preprocessor macros **
- [**JSON_HAS_FILESYSTEM**\
**JSON_HAS_EXPERIMENTAL_FILESYSTEM**](https://json.nlohmann.me/api/macros/json_has_filesystem/index.md) - control `std::filesystem` support
- [**JSON_HAS_RANGES**](https://json.nlohmann.me/api/macros/json_has_ranges/index.md) - control `std::ranges` support
- [**JSON_HAS_STATIC_RTTI**](https://json.nlohmann.me/api/macros/json_has_static_rtti/index.md) - control RTTI (run time type information) support
- [**JSON_HAS_STD_FORMAT**](https://json.nlohmann.me/api/macros/json_has_std_format/index.md) - control `std::format`/`std::formatter` support
- [**JSON_HAS_THREE_WAY_COMPARISON**](https://json.nlohmann.me/api/macros/json_has_three_way_comparison/index.md) - control 3-way comparison support
- [**JSON_NO_AUTOMATIC_UDLS**](https://json.nlohmann.me/api/macros/json_no_automatic_udls/index.md) - do not include the user-defined string literals (UDLs) automatically
+2 -2
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.
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -28,7 +28,7 @@ Therefore, assertions can be switched off by defining `NDEBUG`.
## Examples
Example 1: default behavior
Example: default behavior
The following code will trigger an assertion at runtime:
@@ -50,7 +50,7 @@ Output:
Assertion failed: (m_value.object->find(key) != m_value.object->end()), function operator[], file json.hpp, line 2144.
```
Example 2: user-defined behavior
Example: user-defined behavior
The assertion reporting can be changed by defining `JSON_ASSERT(x)` differently.
+2 -2
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:
File diff suppressed because one or more lines are too long
@@ -59,7 +59,7 @@ json j = json::array({obj}); // always creates [obj]
## Examples
Default behavior (macro not defined)
Example: default behavior (macro not defined)
Without the macro, single-element brace initialization wraps the value in an array:
@@ -77,7 +77,7 @@ int main()
}
```
Opt-in copy semantics (macro defined to 1)
Example: opt-in copy semantics (macro defined to 1)
With the macro, single-element brace initialization copies/moves the value:
@@ -103,4 +103,4 @@ int main()
## Version history
- Added in version 3.13.0.
- Added in version 3.13.0 unreleased.
+2 -2
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"
File diff suppressed because one or more lines are too long
@@ -161,7 +161,7 @@ Parsed string:
The output shows the start/end positions of all the objects and fields in the JSON string.
Example 2: using only diagnostic positions in exceptions
Example: using only diagnostic positions in exceptions
```
#include <iostream>
@@ -206,7 +206,7 @@ Output:
The output shows the exception with start/end positions only.
```
Example 3: using extended diagnostics with positions enabled in exceptions
Example: using extended diagnostics with positions enabled in exceptions
```
#include <iostream>
+3 -3
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"
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -34,7 +34,7 @@ Diagnostic messages can also be controlled with the CMake option [`JSON_Diagnost
## Examples
Example 1: default behavior
Example: default behavior
```
#include <iostream>
@@ -67,7 +67,7 @@ Output:
This exception can be hard to debug if storing the value `"12"` and accessing it is further apart.
Example 2: extended diagnostic messages
Example: extended diagnostic messages
```
#include <iostream>
@@ -102,7 +102,7 @@ Output:
Now the exception message contains a JSON Pointer `/address/housenumber` that indicates which value has the wrong type.
Example 3: using only diagnostic positions in exceptions
Example: using only diagnostic positions in exceptions
```
#include <iostream>
@@ -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.
File diff suppressed because one or more lines are too long
@@ -26,7 +26,7 @@ Enum serialization can also be controlled with the CMake option [`JSON_DisableEn
## Examples
Example 1: Disabled behavior
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.
@@ -52,7 +52,7 @@ int main()
}
```
Example 2: Serialize enum macro
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`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum/index.md) to parse and serialize the enum.
@@ -84,7 +84,7 @@ int main()
}
```
Example 3: User-defined serialization/deserialization functions
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.
@@ -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
File diff suppressed because one or more lines are too long
@@ -57,7 +57,7 @@ This behavior can also be controlled with the CMake option [`JSON_DisableTupleRe
## Examples
Default behavior (macro not defined)
Example: default behavior (macro not defined)
```
#include <nlohmann/json.hpp>
@@ -73,7 +73,7 @@ int main()
}
```
Conversion disabled (macro defined to 1)
Example: conversion disabled (macro defined to 1)
```
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION 1
@@ -100,4 +100,4 @@ int main()
## Version history
- Added in version 3.13.0.
- Added in version 3.13.0 unreleased.
+7
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.
File diff suppressed because one or more lines are too long
+8 -1
View File
@@ -33,8 +33,15 @@ The code below forces the library to use the C++14 standard:
...
```
## See also
- [JSON_HAS_FILESYSTEM / JSON_HAS_EXPERIMENTAL_FILESYSTEM](https://json.nlohmann.me/api/macros/json_has_filesystem/index.md) - control `std::filesystem` support
- [JSON_HAS_RANGES](https://json.nlohmann.me/api/macros/json_has_ranges/index.md) - control `std::ranges` support
- [JSON_HAS_THREE_WAY_COMPARISON](https://json.nlohmann.me/api/macros/json_has_three_way_comparison/index.md) - control 3-way comparison support
- [JSON_HAS_STD_FORMAT](https://json.nlohmann.me/api/macros/json_has_std_format/index.md) - control `std::format`/`std::formatter` support
## Version history
- Added in version 3.10.5.
- Added `JSON_HAS_CPP_23` in version 3.12.0.
- Added `JSON_HAS_CPP_26` in version 3.13.0.
- Added `JSON_HAS_CPP_26` in version 3.13.0 unreleased.
+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.
File diff suppressed because one or more lines are too long
+4
View File
@@ -42,6 +42,10 @@ The code below forces the library to use the header `<experimental/filesystem>`.
...
```
## 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](https://json.nlohmann.me/api/macros/json_has_cpp_11/index.md) - set supported C++ standard
## Version history
- Added in version 3.10.5.
+7
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.
File diff suppressed because one or more lines are too long
+5
View File
@@ -37,6 +37,11 @@ The code below forces the library to enable support for ranges:
...
```
## 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](https://json.nlohmann.me/api/macros/json_has_cpp_11/index.md) - set supported C++ standard
- [JSON_HAS_STD_FORMAT](https://json.nlohmann.me/api/macros/json_has_std_format/index.md) - a similar feature-detection macro, for `std::format`/`std::formatter` support
## Version history
- Added in version 3.11.0.
+6 -1
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.
File diff suppressed because one or more lines are too long
+4
View File
@@ -25,6 +25,10 @@ The code below forces the library to enable support for libraries with RTTI depe
...
```
## See also
- [**operator ValueType**](https://json.nlohmann.me/api/basic_json/operator_ValueType/index.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.
+4
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.
File diff suppressed because one or more lines are too long
+5 -1
View File
@@ -31,6 +31,10 @@ The code below forces the library to disable support for `std::format`, even if
...
```
## See also
- [`std::formatter<basic_json>`](https://json.nlohmann.me/api/basic_json/std_formatter/index.md) - format JSON values with `std::format`
## Version history
- Added in version 3.13.0.
- Added in version 3.13.0 unreleased.
@@ -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.
File diff suppressed because one or more lines are too long
@@ -25,6 +25,11 @@ The code below forces the library to use 3-way comparison:
...
```
## See also
- [**operator\<=>**](https://json.nlohmann.me/api/basic_json/operator_spaceship/index.md) - 3-way compare JSON values
- [**operator==**](https://json.nlohmann.me/api/json_pointer/operator_eq/index.md) - compare JSON pointers for equality
## Version history
- Added in version 3.11.0.
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -56,4 +56,4 @@ Without the include of `<nlohmann/json_literals.hpp>`, the code would fail to co
## Version history
- Added in version 3.13.0.
- Added in version 3.13.0 unreleased.
+5
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.
File diff suppressed because one or more lines are too long
+5
View File
@@ -27,6 +27,11 @@ The code below forces the library not to use the headers `<cstdio>`, `<ios>`, `<
...
```
## See also
- [**operator\<<**](https://json.nlohmann.me/api/operator_ltlt/index.md) - serialize to stream
- [**operator>>**](https://json.nlohmann.me/api/operator_gtgt/index.md) - deserialize from stream
## Version history
- Added in version 3.10.0.
+5 -1
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.
File diff suppressed because one or more lines are too long
+5 -1
View File
@@ -33,6 +33,10 @@ The code below forces the library not to use `thread_local` storage.
...
```
## See also
- [FAQ: Thread safety](https://json.nlohmann.me/home/faq/#thread-safety)
## Version history
- Added in version 3.12.1.
- Added in version 3.13.0 unreleased.
File diff suppressed because one or more lines are too long
+2 -2
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:
File diff suppressed because one or more lines are too long
@@ -64,7 +64,7 @@ Separate the values in the stream with whitespace. The character consumed after
## Examples
Default behavior (macro not defined)
Example: default behavior (macro not defined)
Without the macro, the character after a number is consumed:
@@ -84,7 +84,7 @@ int main()
}
```
Opt-in precise stream position (macro defined to 1)
Example: opt-in precise stream position (macro defined to 1)
With the macro, the stream is positioned right after the number:
@@ -112,5 +112,5 @@ int main()
## Version history
- Added in version 3.13.0.
- Added in version 3.13.0 unreleased.
- Planned to become the default (with the macro removed) in version 4.0.0.
@@ -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.
File diff suppressed because one or more lines are too long
@@ -22,7 +22,7 @@ Mixing different library versions in the same code can be a problem as the diffe
## Examples
Example
Example: switch off the version check
The code below switches off the warning about including a different version of the library.
@@ -33,7 +33,7 @@ The code below switches off the warning about including a different version of t
...
```
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:
@@ -41,6 +41,10 @@ The following warning will be shown in case a different version of the library w
Already included a different version of the library!
```
## See also
- [NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR, NLOHMANN_JSON_VERSION_PATCH](https://json.nlohmann.me/api/macros/nlohmann_json_version_major/index.md) - library version information
## Version history
Added in version 3.11.0.
- Added in version 3.11.0.
@@ -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.
File diff suppressed because one or more lines are too long
@@ -27,6 +27,10 @@ The code below switches off the check whether the compiler is supported.
...
```
## 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](https://json.nlohmann.me/api/macros/json_has_cpp_11/index.md) - set supported C++ standard
## Version history
Added in version 3.2.0.
- Added in version 3.2.0.
+3 -2
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
File diff suppressed because one or more lines are too long
+4 -3
View File
@@ -56,7 +56,7 @@ json::parse(s);
## Examples
Default behavior (macro not defined)
Example: default behavior (macro not defined)
Without the macro, a NUL byte silently ends parsing at that point:
@@ -72,7 +72,7 @@ int main()
}
```
Opt-in strict handling (macro defined to 1)
Example: opt-in strict handling (macro defined to 1)
With the macro, a NUL byte is rejected like any other unexpected byte:
@@ -95,6 +95,7 @@ int main()
## See also
- [JSON_StrictNulHandling](https://json.nlohmann.me/integration/cmake/#json_strictnulhandling) - CMake option to control the macro
- [FAQ: NUL bytes in the input](https://json.nlohmann.me/home/faq/#nul-bytes-in-the-input)
- [**parse**](https://json.nlohmann.me/api/basic_json/parse/index.md) - deserialize from a compatible input
- [**accept**](https://json.nlohmann.me/api/basic_json/accept/index.md) - check if the input is valid JSON
@@ -102,5 +103,5 @@ int main()
## Version history
- Added in version 3.13.0.
- Added in version 3.13.0 unreleased.
- Planned to become the default (with the macro removed) in version 4.0.0.
File diff suppressed because one or more lines are too long
+4 -2
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`.
File diff suppressed because one or more lines are too long
+4 -2
View File
@@ -24,6 +24,8 @@ The user-defined string literals will be removed from the global namespace in th
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](https://json.nlohmann.me/integration/migration_guide/#import-namespace-literals-for-udls) for how to update existing code.
CMake option
The placement of user-defined string literals can also be controlled with the CMake option [`JSON_GlobalUDLs`](https://json.nlohmann.me/integration/cmake/#json_globaludls) (`ON` by default) which defines `JSON_USE_GLOBAL_UDLS` accordingly.
@@ -34,7 +36,7 @@ If [`JSON_NO_AUTOMATIC_UDLS`](https://json.nlohmann.me/api/macros/json_no_automa
## Examples
Example 1: Default behavior
Example: Default behavior
The code below shows the default behavior using the `_json` UDL.
@@ -57,7 +59,7 @@ Output:
42
```
Example 2: Namespaced UDLs
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`.
@@ -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
File diff suppressed because one or more lines are too long
@@ -22,6 +22,8 @@ Implicit conversions will be switched off by default in the next major release o
You can prepare existing code by already defining `JSON_USE_IMPLICIT_CONVERSIONS` to `0` and replace any implicit conversions with calls to [`get`](https://json.nlohmann.me/api/basic_json/get/index.md).
See the [migration guide](https://json.nlohmann.me/integration/migration_guide/#replace-implicit-conversions) for how to update existing code.
Automatic migration
The community-maintained clang-tidy check `modernize-nlohmann-json-explicit-conversions` rewrites implicit conversions into explicit calls to [`get`](https://json.nlohmann.me/api/basic_json/get/index.md); for example, `int i = j;` becomes `int i = j.get<int>();`. The check is not part of clang-tidy itself, and it does not catch every case (for example, constructing a `std::optional` from a JSON value), so review the result. See [discussion #4610](https://github.com/nlohmann/json/discussions/4610) for how to build and use it.
@@ -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
File diff suppressed because one or more lines are too long
@@ -48,6 +48,8 @@ The legacy comparison behavior is deprecated and may be removed in a future majo
New code should not depend on it and existing code should try to remove or rewrite expressions relying on it.
See the [migration guide](https://json.nlohmann.me/integration/migration_guide/#miscellaneous-functions) for how to update existing code.
CMake option
Legacy comparison can also be controlled with the CMake option [`JSON_LegacyDiscardedValueComparison`](https://json.nlohmann.me/integration/cmake/#json_legacydiscardedvaluecomparison) (`OFF` by default) which defines `JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON` accordingly.
+9 -3
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
File diff suppressed because one or more lines are too long
+6 -2
View File
@@ -48,8 +48,12 @@ target_link_libraries(your_target PRIVATE simdutf::simdutf)
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`](https://json.nlohmann.me/integration/cmake/#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
- [JSON_TestSimdutf](https://json.nlohmann.me/integration/cmake/#json_testsimdutf) - CMake option to build the unit tests against the simdutf backend
## Version history
- Added in version 3.13.0.
- Added in version 3.13.0 unreleased.
+1 -1
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:
File diff suppressed because one or more lines are too long
@@ -131,7 +131,7 @@ See Implementation limits for [NLOHMANN_DEFINE_TYPE_INTRUSIVE](https://json.nloh
## Examples
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE
Example: (1) NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE
Consider the following complete example:
+3 -3
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"
File diff suppressed because one or more lines are too long
@@ -66,7 +66,7 @@ Implementation limits
## Examples
Example (1): NLOHMANN_DEFINE_TYPE_INTRUSIVE
Example: (1) NLOHMANN_DEFINE_TYPE_INTRUSIVE
Consider the following complete example:
@@ -202,7 +202,7 @@ int main()
}
```
Example (2): NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT
Example: (2) NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT
Consider the following complete example:
@@ -329,7 +329,7 @@ int main()
Note how a default-initialized `person` object is used in the `from_json` to fill missing values.
Example (3): NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE
Example: (3) NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE
Consider the following complete example:
@@ -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:
File diff suppressed because one or more lines are too long
@@ -65,7 +65,7 @@ Implementation limits
## Examples
Example (1): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
Example: (1) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
Consider the following complete example:
@@ -187,7 +187,7 @@ int main()
}
```
Example (2): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT
Example: (2) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT
Consider the following complete example:
@@ -310,7 +310,7 @@ int main()
Note how a default-initialized `person` object is used in the `from_json` to fill missing values.
Example (3): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE
Example: (3) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE
Consider the following complete example:
+17 -2
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.
File diff suppressed because one or more lines are too long
@@ -33,7 +33,7 @@ For further information please refer to the corresponding macros without `WITH_N
## Examples
Example (1): NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES
Example: NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES
Consider the following complete example:
@@ -155,6 +155,13 @@ int main()
}
```
## See also
- [NLOHMANN_DEFINE_TYPE_INTRUSIVE, NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE](https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/index.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](https://json.nlohmann.me/api/macros/nlohmann_define_type_non_intrusive/index.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](https://json.nlohmann.me/api/macros/nlohmann_define_derived_type/index.md) - similar macros for derived types, also available with custom names
- [Arbitrary Type Conversions](https://json.nlohmann.me/features/arbitrary_types/index.md) - overview of type conversion mechanisms
## Version history
1. Added in version 3.13.0.
- Added in version 3.13.0 unreleased.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -2
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
File diff suppressed because one or more lines are too long
@@ -38,7 +38,7 @@ Important notes
## Examples
Example 1: Basic usage
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:
@@ -112,7 +112,7 @@ ns::TS_STOPPED -> "stopped", ns::Color::red -> "red"
3.14 -> -1, 3.14 -> 3
```
Example 2: Multiple conversions for one enumerator
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 alternative *deserialization* from `"rot"` to `Color::red`.
@@ -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`
File diff suppressed because one or more lines are too long
@@ -38,7 +38,7 @@ Important notes
## Examples
Example 1: Basic usage
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:
@@ -104,7 +104,7 @@ ns::TS_STOPPED -> "stopped", ns::Color::red -> "red"
"running" -> 1, "blue" -> 2
```
Example 2: Multiple conversions for one enumerator
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 alternative *deserialization* from `"rot"` to `Color::red`.
@@ -152,7 +152,7 @@ Output:
"red" -> 0
```
Example 3: exceptions on invalid serialization
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` so causes an exception when used to serialize. Similarly, "what" does not refer to an enum value so also causes an exception when deserialization is attempted.
@@ -227,4 +227,4 @@ deserialization failed: [json.exception.out_of_range.410] enum value out of rang
## Version history
Added in version 3.13.0.
Added in version 3.13.0 unreleased.
File diff suppressed because one or more lines are too long