📝 fix docs (#5217)

This commit is contained in:
Niels Lohmann
2026-06-29 22:15:18 +02:00
committed by GitHub
parent c37f82e563
commit c5b2b26fdc
93 changed files with 743 additions and 1209 deletions
@@ -92,4 +92,4 @@ The default value is `0` (disabled — existing behavior is preserved).
## Version history
- Added in version 3.12.0.
- Added in version 3.12.x.
@@ -122,14 +122,13 @@ The default value is `0`.
void to_json(json& j, const Choice& ch)
{
auto value = j.get<std::string>();
if (value == "first")
if (ch == Choice::first)
{
ch = Choice::first;
j = "first";
}
else if (value == "second")
else if (ch == Choice::second)
{
ch = Choice::second;
j = "second";
}
}
@@ -1,10 +1,12 @@
# JSON_HAS_CPP_11, JSON_HAS_CPP_14, JSON_HAS_CPP_17, JSON_HAS_CPP_20
# JSON_HAS_CPP_11, JSON_HAS_CPP_14, JSON_HAS_CPP_17, JSON_HAS_CPP_20, JSON_HAS_CPP_23, JSON_HAS_CPP_26
```cpp
#define JSON_HAS_CPP_11
#define JSON_HAS_CPP_14
#define JSON_HAS_CPP_17
#define JSON_HAS_CPP_20
#define JSON_HAS_CPP_23
#define JSON_HAS_CPP_26
```
The library targets C++11, but also supports some features introduced in later C++ versions (e.g., `std::string_view`
@@ -20,7 +22,9 @@ The default value is detected based on preprocessor macros such as `#!cpp __cplu
## Notes
- `#!cpp JSON_HAS_CPP_11` is always defined.
- When the C++ standard is detected automatically, `#!cpp JSON_HAS_CPP_11` is always defined. When you override the
detection by defining one of these macros manually, the automatic detection is skipped entirely, so you should define
all applicable macros (including `#!cpp JSON_HAS_CPP_11`) yourself.
- All macros are undefined outside the library.
## Examples
@@ -39,3 +43,5 @@ The default value is detected based on preprocessor macros such as `#!cpp __cplu
## 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.12.x.
@@ -21,7 +21,7 @@ The default value is detected based on the preprocessor macros `#!cpp __cpp_lib_
## Notes
- Note that older compilers or older versions of libstd++ also require the library `stdc++fs` to be linked to for
- Note that older compilers or older versions of libstdc++ also require the library `stdc++fs` to be linked to for
filesystem support.
- Both macros are undefined outside the library.
@@ -24,6 +24,17 @@ By default, the macro is not defined.
## Examples
??? example
The code below switches off the warning about including a different version of the library.
```cpp
#define JSON_SKIP_LIBRARY_VERSION_CHECK 1
#include <nlohmann/json.hpp>
...
```
!!! example
The following warning will be shown in case a different version of the library was already included:
@@ -56,7 +56,7 @@ When the macro is not defined, the library will define it to its default value.
!!! hint "CMake option"
Legacy comparison can also be controlled with the CMake option
[`JSON_LegacyDiscardedValueComparison`](../../integration/cmake.md#json_implicitconversions)
[`JSON_LegacyDiscardedValueComparison`](../../integration/cmake.md#json_legacydiscardedvaluecomparison)
(`OFF` by default) which defines `JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON` accordingly.
## Examples
@@ -72,7 +72,7 @@ When the macro is not defined, the library will define it to its default value.
...
```
### See also
## See also
- [:simple-cmake: JSON_LegacyDiscardedValueComparison](../../integration/cmake.md#json_legacydiscardedvaluecomparison) - CMake option to control the macro
@@ -39,7 +39,7 @@ The base type **must** be already serializable/deserializable.
Summary:
| Need access to private members | Need only de-serialization | Allow missing values when de-serializing | macro |
| Need access to private members | Need only serialization | Allow missing values when de-serializing | macro |
|------------------------------------------------------------------|------------------------------------------------------------------|------------------------------------------------------------------|---------------------------------------------------------------|
| <div style="color: green;">:octicons-check-circle-fill-24:</div> | <div style="color: red;">:octicons-x-circle-fill-24:</div> | <div style="color: red;">:octicons-x-circle-fill-24:</div> | **NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE** |
| <div style="color: green;">:octicons-check-circle-fill-24:</div> | <div style="color: red;">:octicons-x-circle-fill-24:</div> | <div style="color: green;">:octicons-check-circle-fill-24:</div> | **NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT** |
@@ -160,10 +160,10 @@ void to_json(BasicJsonType& j, const B& b) {
## See also
- [NLOHMANN_DEFINE_TYPE_INTRUSIVE / NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT /
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_intrusive.md)
NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_intrusive.md)
for similar macros that can be defined _inside_ a non-derived type.
- [NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE / NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT /
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_non_intrusive.md)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_non_intrusive.md)
for similar macros that can be defined _outside_ a non-derived type.
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) for an overview.
@@ -21,7 +21,7 @@ parameter is the name of the class/struct, and all remaining parameters name the
Summary:
| Need access to private members | Need only de-serialization | Allow missing values when de-serializing | macro |
| Need access to private members | Need only serialization | Allow missing values when de-serializing | macro |
|------------------------------------------------------------------|------------------------------------------------------------------|------------------------------------------------------------------|-------------------------------------------------------|
| <div style="color: green;">:octicons-check-circle-fill-24:</div> | <div style="color: red;">:octicons-x-circle-fill-24:</div> | <div style="color: red;">:octicons-x-circle-fill-24:</div> | **NLOHMANN_DEFINE_TYPE_INTRUSIVE** |
| <div style="color: green;">:octicons-check-circle-fill-24:</div> | <div style="color: red;">:octicons-x-circle-fill-24:</div> | <div style="color: green;">:octicons-check-circle-fill-24:</div> | **NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT** |
@@ -21,7 +21,7 @@ parameter is the name of the class/struct, and all remaining parameters name the
Summary:
| Need access to private members | Need only de-serialization | Allow missing values when de-serializing | macro |
| Need access to private members | Need only serialization | Allow missing values when de-serializing | macro |
|------------------------------------------------------------------|------------------------------------------------------------------|------------------------------------------------------------------|-------------------------------------------------------|
| <div style="color: red;">:octicons-x-circle-fill-24:</div> | <div style="color: red;">:octicons-x-circle-fill-24:</div> | <div style="color: red;">:octicons-x-circle-fill-24:</div> | **NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE** |
| <div style="color: red;">:octicons-x-circle-fill-24:</div> | <div style="color: red;">:octicons-x-circle-fill-24:</div> | <div style="color: green;">:octicons-check-circle-fill-24:</div> | **NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT** |
@@ -75,4 +75,4 @@ For further information please refer to the corresponding macros without `WITH_N
## Version history
1. Added in version 3.11.x.
1. Added in version 3.12.x.
@@ -21,13 +21,13 @@ The default definitions open and close the `nlohmann` namespace. The precise def
```cpp
namespace nlohmann
{
inline namespace json_abi_v3_11_2
inline namespace json_abi_v3_12_0
{
```
2. Default definition of `NLOHMANN_JSON_NAMESPACE_END`:
```cpp
} // namespace json_abi_v3_11_2
} // namespace json_abi_v3_12_0
} // namespace nlohmann
```
@@ -38,7 +38,10 @@ inline void from_json(const BasicJsonType& j, type& e);
!!! important "Important notes"
- When using [`get<ENUM_TYPE>()`](../basic_json/get.md), undefined JSON values will throw an exception.
- Undefined input throws [`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) in both
directions: when serializing an enum value not listed in the conversions, and when deserializing (e.g., via
[`get<ENUM_TYPE>()`](../basic_json/get.md)) a JSON value that matches no conversion; example:
`"enum value out of range for <type>"`.
- If an enum or JSON value is specified in multiple conversions, the first matching conversion from the top of the
list will be returned when converting to or from JSON. See example 2 below.
@@ -99,4 +102,4 @@ inline void from_json(const BasicJsonType& j, type& e);
## Version history
Added in version 3.12.0.
Added in version 3.12.x.