Compare commits

..

5 Commits

Author SHA1 Message Date
Niels Lohmann a397a1fe57 👷 add more MSVC images
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-06-30 07:54:54 +02:00
Niels Lohmann 3d644aef09 👷 add more MSVC images
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-06-30 07:33:56 +02:00
Niels Lohmann 21500de668 🐛 fix nvc++ build
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-06-29 19:47:18 +02:00
Niels Lohmann a0b9149ec5 🐛 fix nvc++ build
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-06-29 14:17:04 +02:00
Niels Lohmann 7c4d469b84 👷 add ipcx and nvc++
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-06-29 09:36:08 +02:00
101 changed files with 1350 additions and 802 deletions
+24
View File
@@ -247,6 +247,30 @@ jobs:
. /opt/intel/oneapi/setvars.sh
cmake --build build --target ci_icpc
ci_icpx:
runs-on: ubuntu-latest
container: intel/oneapi-hpckit:latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Get latest CMake and ninja
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
run: cmake --build build --target ci_icpx
ci_nvhpc:
runs-on: ubuntu-latest
container: nvcr.io/nvidia/nvhpc:25.5-devel-cuda12.9-ubuntu22.04
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Get latest CMake and ninja
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
run: cmake --build build --target ci_nvhpc
ci_emscripten:
runs-on: ubuntu-latest
steps:
+62
View File
@@ -70,6 +70,68 @@ jobs:
- name: Test
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
# Visual Studio 2026 (v145 toolset) on the windows-2025 image. The "Visual Studio
# 18 2026" generator requires CMake 4.2+, so a recent CMake is fetched explicitly.
msvc-vs2026:
strategy:
matrix:
build_type: [Debug, Release]
architecture: [Win32, x64]
std_version: [default, latest]
runs-on: windows-2025
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Get latest CMake and ninja
uses: lukka/get-cmake@f5b8fbb4d77cec1acc5a5f9f0df4beffaf5d98d9 # v4.3.4
- name: Set extra CXX_FLAGS for latest std_version
# /wd5285 silences C5285 emitted by the bundled third-party doctest.h, which
# specializes std::tuple (newly diagnosed by the VS2026 v145 toolset)
run: |
if [ "${{ matrix.std_version }}" = "latest" ]; then
echo "flags=/permissive- /std:c++latest /utf-8 /W4 /WX /wd5285" >> $GITHUB_ENV
else
echo "flags=/W4 /WX /wd5285" >> $GITHUB_ENV
fi
shell: bash
- name: Run CMake (Release)
run: cmake -S . -B build -G "Visual Studio 18 2026" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="$env:flags"
if: matrix.build_type == 'Release'
shell: pwsh
- name: Run CMake (Debug)
run: cmake -S . -B build -G "Visual Studio 18 2026" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="$env:flags"
if: matrix.build_type == 'Debug'
shell: pwsh
- name: Build
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
- name: Test
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
# Native ARM64 Windows runner with the MSVC ARM64 toolset. The windows-11-arm
# label is only available for public repositories.
msvc-arm64:
strategy:
matrix:
build_type: [Debug, Release]
runs-on: windows-11-arm
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Run CMake (Release)
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ARM64 -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
if: matrix.build_type == 'Release'
shell: pwsh
- name: Run CMake (Debug)
run: cmake -S . -B build -G "Visual Studio 17 2022" -A ARM64 -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX"
if: matrix.build_type == 'Debug'
shell: pwsh
- name: Build
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
- name: Test
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
clang:
runs-on: windows-2022
strategy:
+42
View File
@@ -701,6 +701,48 @@ add_custom_target(ci_icpc
COMMENT "Compile and test with ICPC"
)
add_custom_target(ci_icpx
COMMAND ${CMAKE_COMMAND}
-DCMAKE_BUILD_TYPE=Debug -GNinja
-DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
-DJSON_BuildTests=ON -DJSON_FastTests=ON
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_icpx
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_icpx
COMMAND cd ${PROJECT_BINARY_DIR}/build_icpx && ${CMAKE_CTEST_COMMAND} --parallel ${N} --exclude-regex "test-unicode" --output-on-failure
COMMENT "Compile and test with ICPX (Intel oneAPI DPC++/C++)"
)
###############################################################################
# NVIDIA HPC SDK C++ Compiler
###############################################################################
# nvc++ defaults to a relaxed, non-IEEE floating-point model that flushes denormals
# to zero and does not honor NaN ordering; -Kieee restores strict IEEE 754 behavior
# (needed for the dtoa/grisu and NaN-comparison code paths).
#
# The following tests are excluded as they trigger known nvc++ 25.5 defects (not
# library bugs); see https://github.com/nlohmann/json for tracking. Only the
# affected language-standard variants are excluded so coverage is otherwise kept:
# - test-comparison_cpp20, test-comparison_legacy_cpp20
# miscompiles cross-type/<=> comparison (e.g. `-17 <= null`)
# - test-constructor1_cpp11
# std::initializer_list lifetime bug -> SIGSEGV
# - test-deserialization_cpp20
# mangles the UTF-8 u8"" string literal in the char8_t (C++20) section
add_custom_target(ci_nvhpc
COMMAND ${CMAKE_COMMAND}
-DCMAKE_BUILD_TYPE=Debug -GNinja
-DCMAKE_C_COMPILER=nvc -DCMAKE_CXX_COMPILER=nvc++
-DCMAKE_CXX_FLAGS=-Kieee
-DJSON_BuildTests=ON -DJSON_FastTests=ON
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_nvhpc
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_nvhpc
# the pipes are escaped so the surrounding shell passes them to ctest verbatim
# instead of treating them as shell pipe operators
COMMAND cd ${PROJECT_BINARY_DIR}/build_nvhpc && ${CMAKE_CTEST_COMMAND} --parallel ${N} --exclude-regex "test-unicode\\|test-comparison_cpp20\\|test-comparison_legacy_cpp20\\|test-constructor1_cpp11\\|test-deserialization_cpp20" --output-on-failure
COMMENT "Compile and test with NVIDIA HPC SDK (nvc++)"
)
###############################################################################
# REUSE
###############################################################################
@@ -30,8 +30,7 @@ class (either explicitly or via the conversion operators).
## Return value
1. (none) -- the converted value is written to the output parameter `val`.
2. the JSON value `j` converted to `TargetType`
Copy of the JSON value, converted to `ValueType`
## Examples
+1 -2
View File
@@ -101,7 +101,6 @@ A UTF-8 byte order mark is silently ignored.
## See also
- [parse](parse.md) - deserialize from a compatible input
- [sax_parse](sax_parse.md) - parse input using the SAX interface
- [operator>>](../operator_gtgt.md) - deserialize from stream
## Version history
@@ -109,7 +108,7 @@ A UTF-8 byte order mark is silently ignored.
- Added in version 3.0.0.
- Ignoring comments via `ignore_comments` added in version 3.9.0.
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
- Added `ignore_trailing_commas` in version 3.12.x.
- Added `ignore_trailing_commas` in version 3.12.1.
!!! warning "Deprecation"
-2
View File
@@ -82,8 +82,6 @@ Strong exception safety: if an exception occurs, the original value stays intact
key of an object which cannot be found. See the example below.
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if the JSON pointer `ptr` can
not be resolved. See the example below.
- Throws [`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) if an array index in the passed
JSON pointer `ptr` exceeds the range of `size_type` (e.g., on 32-bit platforms).
## Complexity
+1 -1
View File
@@ -9,7 +9,7 @@ The type used to store JSON booleans.
[RFC 8259](https://tools.ietf.org/html/rfc8259) implicitly describes a boolean as a type which differentiates the two
literals `#!json true` and `#!json false`.
To store boolean values in C++, a type is defined by the template parameter `BooleanType` which chooses the type to use.
To store objects in C++, a type is defined by the template parameter `BooleanType` which chooses the type to use.
## Notes
+5 -6
View File
@@ -48,7 +48,11 @@ Strong exception safety: if an exception occurs, the original value stays intact
1. The function does not throw exceptions.
2. The function does not throw exceptions.
3. The function does not throw exceptions.
3. The function can throw the following exceptions:
- Throws [`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) if an array index begins with
`0`.
- Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) if an array index was not a
number.
## Complexity
@@ -107,11 +111,6 @@ Logarithmic in the size of the JSON object.
--8<-- "examples/contains__json_pointer.output"
```
## See also
- [find](find.md) find a value in an object
- [count](count.md) returns the number of occurrences of a key
## Version history
1. Added in version 3.11.0.
-5
View File
@@ -72,11 +72,6 @@ This method always returns `0` when executed on a JSON type that is not an objec
--8<-- "examples/count__keytype.c++17.output"
```
## See also
- [find](find.md) find a value in an object
- [contains](contains.md) checks whether a key exists
## Version history
1. Added in version 3.11.0.
+1 -1
View File
@@ -10,7 +10,7 @@ Returns an iterator to the reverse-beginning; that is, the last element.
## Return value
reverse iterator to the last element
reverse iterator to the first element
## Exception safety
+1 -1
View File
@@ -25,7 +25,7 @@ Constant.
??? example
The following code shows an example for `crend()`.
The following code shows an example for `eend()`.
```cpp
--8<-- "examples/crend.cpp"
-3
View File
@@ -56,9 +56,6 @@ Currently, only `remove`, `add`, and `replace` operations are generated.
## See also
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
- [patch](patch.md) applies a JSON Patch
- [patch_inplace](patch_inplace.md) applies a JSON Patch in place
- [merge_patch](merge_patch.md) applies a JSON Merge Patch
## Version history
+1 -6
View File
@@ -26,7 +26,7 @@ and `ensure_ascii` parameters.
`error_handler` (in)
: how to react on decoding errors; there are three possible values (see [`error_handler_t`](error_handler_t.md):
`strict` (throws an exception in case a decoding error occurs; default), `replace` (replace invalid UTF-8 sequences
`strict` (throws and exception in case a decoding error occurs; default), `replace` (replace invalid UTF-8 sequences
with U+FFFD), and `ignore` (ignore invalid UTF-8 sequences during serialization; all bytes are copied to the output
unchanged)).
@@ -71,11 +71,6 @@ Binary values are serialized as an object containing two keys:
--8<-- "examples/dump.output"
```
## See also
- [to_string](to_string.md) returns a string representation of a JSON value
- [operator<<](../operator_ltlt.md) serialize to stream
## Version history
- Added in version 1.0.0.
@@ -29,10 +29,6 @@ iterators (including the `end()` iterator) and all references to the elements ar
a pair consisting of an iterator to the inserted element, or the already-existing element if no insertion happened, and
a `#!cpp bool` denoting whether the insertion took place.
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
## Exceptions
Throws [`type_error.311`](../../home/exceptions.md#jsonexceptiontype_error311) when called on a type other than JSON
@@ -60,11 +56,6 @@ Logarithmic in the size of the container, O(log(`size()`)).
--8<-- "examples/emplace.output"
```
## See also
- [emplace_back](emplace_back.md) add a value to an array
- [insert](insert.md) add values to an array/object
## Version history
- Since version 2.0.8.
+1 -6
View File
@@ -101,7 +101,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
4. See 3.
5. The function can throw the following exceptions:
- Throws [`type_error.307`](../../home/exceptions.md#jsonexceptiontype_error307) when called on a type other than
JSON array; example: `"cannot use erase() with null"`
JSON object; example: `"cannot use erase() with null"`
- Throws [`out_of_range.401`](../../home/exceptions.md#jsonexceptionout_of_range401) when `idx >= size()`; example:
`"array index 17 is out of range"`
@@ -202,11 +202,6 @@ Strong exception safety: if an exception occurs, the original value stays intact
--8<-- "examples/erase__size_type.output"
```
## See also
- [clear](clear.md) clears the contents
- [insert](insert.md) add values to an array/object
## Version history
1. Added in version 1.0.0. Added support for binary types in version 3.8.0.
-1
View File
@@ -78,7 +78,6 @@ This method always returns `end()` when executed on a JSON type that is not an o
## See also
- [count](count.md) returns the number of occurrences of a key
- [contains](contains.md) checks whether a key exists
## Version history
@@ -67,8 +67,6 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
successfully
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the size of an optimized container
or n-dimensional array cannot be represented by `std::size_t`
## Complexity
@@ -90,14 +88,6 @@ Linear in the size of the input.
--8<-- "examples/from_bjdata.output"
```
## See also
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format
## Version history
- Added in version 3.11.0.
+2 -7
View File
@@ -62,12 +62,8 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
## Exceptions
- Throws [`parse_error.110`](../../home/exceptions.md#jsonexceptionparse_error110) if the given input ends prematurely or
the end of the input was not reached when `strict` was set to true
- Throws [`parse_error.112`](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs (e.g., an
invalid string or byte array length)
- Throws [`parse_error.114`](../../home/exceptions.md#jsonexceptionparse_error114) if an unsupported BSON record type is
encountered
Throws [`parse_error.114`](../../home/exceptions.md#jsonexceptionparse_error114) if an unsupported BSON record type is
encountered.
## Complexity
@@ -96,7 +92,6 @@ Linear in the size of the input.
- [from_cbor](from_cbor.md) for the related CBOR format
- [from_msgpack](from_msgpack.md) for the related MessagePack format
- [from_ubjson](from_ubjson.md) for the related UBJSON format
- [from_bjdata](from_bjdata.md) for the related BJData format
## Version history
@@ -96,14 +96,6 @@ Linear in the size of the input.
--8<-- "examples/from_cbor.output"
```
## See also
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format
## Version history
- Added in version 2.0.9.
@@ -89,14 +89,6 @@ Linear in the size of the input.
--8<-- "examples/from_msgpack.output"
```
## See also
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format
## Version history
- Added in version 2.0.9.
@@ -109,7 +101,7 @@ Linear in the size of the input.
- Overload (2) replaces calls to `from_msgpack` with a pointer and a length as first two parameters, which has been
deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like
`#!cpp from_msgpack(ptr, len, ...);` with `#!cpp from_msgpack(ptr, ptr+len, ...);`.
- Overload (2) replaces calls to `from_msgpack` with a pair of iterators as their first parameter, which has been
- Overload (2) replaces calls to `from_cbor` with a pair of iterators as their first parameter, which has been
deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like
`#!cpp from_msgpack({ptr, ptr+len}, ...);` with `#!cpp from_msgpack(ptr, ptr+len, ...);`.
+1 -11
View File
@@ -65,10 +65,8 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
- Throws [parse_error.110](../../home/exceptions.md#jsonexceptionparse_error110) if the given input ends prematurely or
the end of the file was not reached when `strict` was set to true
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
successfully
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the size of an optimized container
or n-dimensional array cannot be represented by `std::size_t`
## Complexity
@@ -90,14 +88,6 @@ Linear in the size of the input.
--8<-- "examples/from_ubjson.output"
```
## See also
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format
## Version history
- Added in version 3.1.0.
-12
View File
@@ -88,11 +88,6 @@ constexpr const PointerType get_ptr() const noexcept;
Depends on what `json_serializer<ValueType>` `from_json()` method throws
## Complexity
Depends on the `json_serializer<ValueType>::from_json()` implementation for overloads (1) and (2); constant for
overload (3).
## Notes
!!! danger "Undefined behavior for pointers"
@@ -149,13 +144,6 @@ overload (3).
--8<-- "examples/get__PointerType.output"
```
## See also
- [get_to](get_to.md) convert and write into a passed value
- [get_ptr](get_ptr.md) get a pointer to the stored value
- [get_ref](get_ref.md) get a reference to the stored value
- [operator ValueType](operator_ValueType.md) get a value via implicit conversion
## Version history
1. Since version 2.1.0.
@@ -40,11 +40,6 @@ Constant.
--8<-- "examples/get_binary.output"
```
## See also
- [get](get.md) get a value (explicit conversion)
- [get_ref](get_ref.md) get a reference to the stored value
## Version history
- Added in version 3.8.0.
-10
View File
@@ -34,10 +34,6 @@ the input parameter, allowing chaining calls
Depends on what `json_serializer<ValueType>` `from_json()` method throws
## Complexity
Depends on the `json_serializer<ValueType>::from_json()` implementation.
## Examples
??? example
@@ -57,12 +53,6 @@ Depends on the `json_serializer<ValueType>::from_json()` implementation.
--8<-- "examples/get_to.output"
```
## See also
- [get](get.md) get a value (explicit conversion)
- [get_ref](get_ref.md) get a reference to the stored value
- [get_ptr](get_ptr.md) get a pointer to the stored value
## Version history
- Since version 3.3.0.
+2 -9
View File
@@ -96,8 +96,8 @@ Strong exception safety: if an exception occurs, the original value stays intact
5. The function can throw the following exceptions:
- Throws [`type_error.309`](../../home/exceptions.md#jsonexceptiontype_error309) if called on JSON values other than
objects; example: `"cannot use insert() with string"`
- Throws [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202) if `first` or `last`
do not point to an object; example: `"iterators first and last must point to objects"`
- Throws [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202) if called on an
iterator which does not belong to the current JSON value; example: `"iterator does not fit current value"`
- Throws [`invalid_iterator.210`](../../home/exceptions.md#jsonexceptioninvalid_iterator210) if `first` and `last`
do not belong to the same JSON value; example: `"iterators do not fit"`
@@ -181,13 +181,6 @@ Strong exception safety: if an exception occurs, the original value stays intact
--8<-- "examples/insert__range_object.output"
```
## See also
- [emplace](emplace.md) add a value to an object
- [emplace_back](emplace_back.md) add a value to an array
- [push_back](push_back.md) add a value to an array/object
- [update](update.md) merges objects
## Version history
1. Added in version 1.0.0.
@@ -66,7 +66,6 @@ classDiagram
## See also
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
- [List of iterator errors](../../home/exceptions.md#iterator-errors)
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
- [`type_error`](type_error.md) for exceptions indicating executing a member function with a wrong type
@@ -45,13 +45,11 @@ Constant.
When a value is discarded by a callback function (see [`parser_callback_t`](parser_callback_t.md)) during parsing,
then it is removed when it is part of a structured value. For instance, if the second value of an array is discarded,
instead of `#!json [null, discarded, false]`, the array `#!json [null, false]` is returned. If the top-level value
itself is discarded by the callback, the `parse` call returns a `#!json null` value.
instead of `#!json [null, discarded, false]`, the array `#!json [null, false]` is returned. Only if the top-level
value is discarded, the return value of the `parse` call is discarded.
After a successful parse, this function always returns `#!cpp false`: discarded values can only occur during parsing and
are either removed when inside a structured value or replaced by `#!json null` at the top level. The exception is parsing
with `allow_exceptions` set to `#!cpp false`: a parse error then yields a discarded value for which this function returns
`#!cpp true` (see [`parse`](parse.md)).
This function will always be `#!cpp false` for JSON values after parsing. That is, discarded values can only occur
during parsing, but will be removed when inside a structured value or replaced by null in other cases.
## Examples
+1 -1
View File
@@ -9,7 +9,7 @@ unsigned) and floating-point values.
## Return value
`#!cpp true` if type is number (regardless whether integer, unsigned integer, or floating-point), `#!cpp false` otherwise.
`#!cpp true` if type is number (regardless whether integer, unsigned integer, or floating-type), `#!cpp false` otherwise.
## Exception safety
-5
View File
@@ -84,11 +84,6 @@ When iterating over an array, `key()` will return the index of the element as st
--8<-- "examples/items.output"
```
## See also
- [begin](begin.md) returns an iterator to the first element
- [end](end.md) returns an iterator to one past the last element
## Version history
- Added `iterator_wrapper` in version 3.0.0.
+1 -1
View File
@@ -13,7 +13,7 @@ JSON object holding version information
| key | description |
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `compiler` | Information on the used compiler. It is an object with the following keys: `c++` (the used C++ standard), `family` (the compiler family; possible values are `clang`, `icc`, `gcc`, `ilecpp`, `msvc`, `pgcpp`, `sunpro`, and `unknown`), and `version` (the compiler version). On HP aCC compilers, `compiler` is instead the plain string `hp`. |
| `compiler` | Information on the used compiler. It is an object with the following keys: `c++` (the used C++ standard), `family` (the compiler family; possible values are `clang`, `icc`, `gcc`, `ilecpp`, `msvc`, `pgcpp`, `sunpro`, and `unknown`), and `version` (the compiler version). |
| `copyright` | The copyright line for the library as string. |
| `name` | The name of the library as string. |
| `platform` | The used platform as string. Possible values are `win32`, `linux`, `apple`, `unix`, and `unknown`. |
@@ -32,6 +32,7 @@ With the default values for `NumberIntegerType` (`std::int64_t`), the default va
- The restrictions about leading zeros are not enforced in C++. Instead, leading zeros in integer literals lead to an
interpretation as an octal number. Internally, the value will be stored as a decimal number. For instance, the C++
integer literal `010` will be serialized to `8`. During deserialization, leading zeros yield an error.
- Not-a-number (NaN) values will be serialized to `null`.
#### Limits
@@ -32,6 +32,7 @@ With the default values for `NumberUnsignedType` (`std::uint64_t`), the default
- The restrictions about leading zeros are not enforced in C++. Instead, leading zeros in integer literals lead to an
interpretation as an octal number. Internally, the value will be stored as a decimal number. For instance, the C++
integer literal `010` will be serialized to `8`. During deserialization, leading zeros yield an error.
- Not-a-number (NaN) values will be serialized to `null`.
#### Limits
@@ -44,7 +45,7 @@ when used in a constructor. During deserialization, too large or small integer n
as [`number_integer_t`](number_integer_t.md) or [`number_float_t`](number_float_t.md).
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
> Note that when such software is used, numbers that are integers and are in the range $[-2^{53}+1, 2^{53}-1]$ are
> Note that when such software is used, numbers that are integers and are in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are
> interoperable in the sense that implementations will agree exactly on their numeric values.
As this range is a subrange (when considered in conjunction with the `number_integer_t` type) of the exactly supported
@@ -50,12 +50,9 @@ invalidates all iterators and all references.
## Exceptions
1. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
JSON array or null; example: `"cannot use push_back() with number"`
2. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
JSON object or null; example: `"cannot use push_back() with number"`
3. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
JSON array or null; example: `"cannot use push_back() with number"`
All functions can throw the following exception:
- Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
JSON array or null; example: `"cannot use operator+=() with number"`
## Complexity
+1 -11
View File
@@ -5,8 +5,7 @@ basic_json& operator=(basic_json other) noexcept (
std::is_nothrow_move_constructible<value_t>::value &&
std::is_nothrow_move_assignable<value_t>::value &&
std::is_nothrow_move_constructible<json_value>::value &&
std::is_nothrow_move_assignable<json_value>::value &&
std::is_nothrow_move_assignable<json_base_class_t>::value
std::is_nothrow_move_assignable<json_value>::value
);
```
@@ -18,10 +17,6 @@ constructor, destructor, and the `swap()` member function.
`other` (in)
: value to copy from
## Exception safety
Strong guarantee: if an exception is thrown while copying `other`, there are no changes to `#!cpp *this`.
## Complexity
Linear.
@@ -43,11 +38,6 @@ Linear.
--8<-- "examples/basic_json__copyassignment.output"
```
## See also
- [basic_json](basic_json.md) create a JSON value
- [swap](swap.md) exchanges the contents of two JSON values
## Version history
- Added in version 1.0.0.
@@ -83,8 +83,6 @@ Strong exception safety: if an exception occurs, the original value stays intact
in the passed JSON pointer `ptr` for the const version.
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if the JSON pointer `ptr` can
not be resolved.
- Throws [`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) if an array index in the passed
JSON pointer `ptr` exceeds the range of `size_type` (e.g., on 32-bit platforms).
## Complexity
@@ -97,10 +95,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
!!! danger "Undefined behavior and runtime assertions"
The following cases apply to the **const** overloads; the non-const overloads instead insert the missing element
(see the notes below).
1. If the element at index `idx` does not exist, the behavior is undefined.
1. If the element with key `idx` does not exist, the behavior is undefined.
2. If the element with key `key` does not exist, the behavior is undefined and is **guarded by a
[runtime assertion](../../features/assertions.md)**!
@@ -75,10 +75,6 @@ Linear in the size of the JSON value.
--8<-- "examples/operator__ValueType.output"
```
## See also
- [get](get.md) get a value (explicit conversion)
## Version history
- Since version 1.0.0.
@@ -20,7 +20,7 @@ class basic_json {
```
1. Compares two JSON values for equality according to the following rules:
- Two JSON values are equal if (1) neither value is discarded, and (2) they are of the same type and their stored
- Two JSON values are equal if (1) neither value is discarded, or (2) they are of the same type and their stored
values are the same according to their respective `operator==`.
- Integer and floating-point numbers are automatically converted before comparison.
@@ -79,13 +79,13 @@ Linear.
}
```
Or you can define your own equality function like this:
Or you can self-defined operator equal function like this:
```cpp
bool my_equal(const_reference lhs, const_reference rhs)
{
const auto lhs_type = lhs.type();
const auto rhs_type = rhs.type();
const auto lhs_type lhs.type();
const auto rhs_type rhs.type();
if (lhs_type == rhs_type)
{
switch(lhs_type)
@@ -162,11 +162,6 @@ Linear.
--8<-- "examples/operator__equal__nullptr_t.output"
```
## See also
- [operator!=](operator_ne.md) compare for inequality
- [operator<=>](operator_spaceship.md) comparison: 3-way (C++20)
## Version history
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
@@ -35,7 +35,7 @@ bool operator>=(ScalarType lhs, const const_reference rhs) noexcept; // (2)
## Return value
whether `lhs` is greater than or equal to `rhs`
whether `lhs` is less than or equal to `rhs`
## Exception safety
@@ -66,7 +66,6 @@ classDiagram
## See also
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
- [List of other errors](../../home/exceptions.md#further-exceptions)
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
@@ -67,7 +67,6 @@ classDiagram
## See also
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
- [List of out-of-range errors](../../home/exceptions.md#out-of-range)
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
+5 -6
View File
@@ -81,6 +81,9 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
- Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token, or
empty input like a null `FILE*` or `char*` pointer.
- Throws [`parse_error.102`](../../home/exceptions.md#jsonexceptionparse_error102) if `to_unicode` fails or surrogate
error.
- Throws [`parse_error.103`](../../home/exceptions.md#jsonexceptionparse_error103) if `to_unicode` fails.
## Complexity
@@ -92,9 +95,6 @@ super-linear complexity.
A UTF-8 byte order mark is silently ignored.
Invalid Unicode escapes and unpaired surrogates in the input are reported as
[`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) with a detailed message.
## Examples
??? example "Parsing from a character array"
@@ -183,7 +183,7 @@ Invalid Unicode escapes and unpaired surrogates in the input are reported as
??? example "Effect of `allow_exceptions` parameter"
The example below demonstrates the effect of the `allow_exceptions` parameter in the `parse()` function.
The example below demonstrates the effect of the `allow_exceptions` parameter in the ´parse()` function.
```cpp
--8<-- "examples/parse__allow_exceptions.cpp"
@@ -226,7 +226,6 @@ Invalid Unicode escapes and unpaired surrogates in the input are reported as
## See also
- [accept](accept.md) - check if the input is valid JSON
- [sax_parse](sax_parse.md) - parse input using the SAX interface
- [operator>>](../operator_gtgt.md) - deserialize from stream
## Version history
@@ -235,7 +234,7 @@ Invalid Unicode escapes and unpaired surrogates in the input are reported as
- Overload for contiguous containers (1) added in version 2.0.3.
- Ignoring comments via `ignore_comments` added in version 3.9.0.
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
- Added `ignore_trailing_commas` in version 3.12.x.
- Added `ignore_trailing_commas` in version 3.12.1.
!!! warning "Deprecation"
@@ -75,7 +75,6 @@ or the end of file. This also holds true when reading a byte vector for binary f
## See also
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
- [List of parse errors](../../home/exceptions.md#parse-errors)
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
- [`type_error`](type_error.md) for exceptions indicating executing a member function with a wrong type
@@ -24,11 +24,6 @@ The parser callback distinguishes the following events:
![Example when certain parse events are triggered](../../images/callback_events.png)
## See also
- [parser_callback_t](parser_callback_t.md) callback function type for the parser
- [parse](parse.md) deserialize from a compatible input
## Version history
- Added in version 1.0.0.
@@ -68,11 +68,6 @@ the latter case, it is either skipped completely or replaced by an empty discard
--8<-- "examples/parse__string__parser_callback_t.output"
```
## See also
- [parse](parse.md) deserialize from a compatible input
- [parse_event_t](parse_event_t.md) enumeration of parser events
## Version history
- Added in version 1.0.0.
+1 -1
View File
@@ -32,7 +32,7 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
could not be resolved successfully in the current JSON value; example: `"key baz not found"`.
- Throws [`out_of_range.405`](../../home/exceptions.md#jsonexceptionout_of_range405) if JSON pointer has no parent
("add", "remove", "move")
- Throws [`other_error.501`](../../home/exceptions.md#jsonexceptionother_error501) if "test" operation was
- Throws [`out_of_range.501`](../../home/exceptions.md#jsonexceptionother_error501) if "test" operation was
unsuccessful.
## Complexity
@@ -1,7 +1,7 @@
# <small>nlohmann::basic_json::</small>patch_inplace
```cpp
void patch_inplace(const basic_json& json_patch);
void patch_inplace(const basic_json& json_patch) const;
```
[JSON Patch](http://jsonpatch.com) defines a JSON document structure for expressing a sequence of operations to apply to
@@ -28,7 +28,7 @@ No guarantees, value may be corrupted by an unsuccessful patch operation.
could not be resolved successfully in the current JSON value; example: `"key baz not found"`.
- Throws [`out_of_range.405`](../../home/exceptions.md#jsonexceptionout_of_range405) if JSON pointer has no parent
("add", "remove", "move")
- Throws [`other_error.501`](../../home/exceptions.md#jsonexceptionother_error501) if "test" operation was
- Throws [`out_of_range.501`](../../home/exceptions.md#jsonexceptionother_error501) if "test" operation was
unsuccessful.
## Complexity
@@ -62,7 +62,7 @@ function throws an exception.
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
- [RFC 6901 (JSON Pointer)](https://tools.ietf.org/html/rfc6901)
- [patch](patch.md) applies a JSON Patch
- [patch](patch.md) applies a JSON Merge Patch
- [merge_patch](merge_patch.md) applies a JSON Merge Patch
## Version history
+3 -6
View File
@@ -46,12 +46,9 @@ invalidates all iterators and all references.
## Exceptions
1. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
JSON array or null; example: `"cannot use push_back() with number"`
2. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
JSON object or null; example: `"cannot use push_back() with number"`
3. Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
JSON array or null; example: `"cannot use push_back() with number"`
All functions can throw the following exception:
- Throws [`type_error.308`](../../home/exceptions.md#jsonexceptiontype_error308) when called on a type other than
JSON array or null; example: `"cannot use push_back() with number"`
## Complexity
+1 -1
View File
@@ -11,7 +11,7 @@ Returns an iterator to the reverse-beginning; that is, the last element.
## Return value
reverse iterator to the last element
reverse iterator to the first element
## Exception safety
+1 -1
View File
@@ -26,7 +26,7 @@ Constant.
??? example
The following code shows an example for `rend()`.
The following code shows an example for `eend()`.
```cpp
--8<-- "examples/rend.cpp"
+6 -9
View File
@@ -43,11 +43,10 @@ The SAX event lister must follow the interface of [`json_sax`](../json_sax/index
iterators.
`IteratorType`
: a compatible iterator type for overload (2); a pair of character iterators whose `value_type` is an integral type
with a size of 1, 2, or 4 bytes (interpreted respectively as UTF-8, UTF-16, and UTF-32)
: Description
`SAX`
: a class fulfilling the SAX event listener interface; see [`json_sax`](../json_sax/index.md)
: Description
## Parameters
@@ -90,6 +89,9 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
- Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token, or
empty input like a null `FILE*` or `char*` pointer.
- Throws [`parse_error.102`](../../home/exceptions.md#jsonexceptionparse_error102) if `to_unicode` fails or surrogate
error.
- Throws [`parse_error.103`](../../home/exceptions.md#jsonexceptionparse_error103) if `to_unicode` fails.
## Complexity
@@ -117,16 +119,11 @@ A UTF-8 byte order mark is silently ignored.
--8<-- "examples/sax_parse.output"
```
## See also
- [parse](parse.md) - deserialize from a compatible input
- [accept](accept.md) - check if the input is valid JSON
## Version history
- Added in version 3.2.0.
- Ignoring comments via `ignore_comments` added in version 3.9.0.
- Added `ignore_trailing_commas` in version 3.12.x.
- Added `ignore_trailing_commas` in version 3.12.1.
!!! warning "Deprecation"
@@ -16,14 +16,6 @@ Exchanges the values of two JSON objects.
`j2` (in, out)
: value to be replaced by `j1`
## Exception safety
No-throw guarantee: this function never throws exceptions.
## Complexity
Constant.
## Possible implementation
```cpp
+1 -1
View File
@@ -9,7 +9,7 @@ The type used to store JSON strings.
[RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON strings as follows:
> A string is a sequence of zero or more Unicode characters.
To store strings in C++, a type is defined by the template parameter described below. Unicode values are split by the
To store objects in C++, a type is defined by the template parameter described below. Unicode values are split by the
JSON class into byte-sized characters during deserialization.
## Template parameters
+8 -20
View File
@@ -2,20 +2,10 @@
```cpp
// (1)
void swap(reference other) noexcept (
std::is_nothrow_move_constructible<value_t>::value &&
std::is_nothrow_move_assignable<value_t>::value &&
std::is_nothrow_move_constructible<json_value>::value &&
std::is_nothrow_move_assignable<json_value>::value
);
void swap(reference other) noexcept;
// (2)
friend void swap(reference left, reference right) noexcept (
std::is_nothrow_move_constructible<value_t>::value &&
std::is_nothrow_move_assignable<value_t>::value &&
std::is_nothrow_move_constructible<json_value>::value &&
std::is_nothrow_move_assignable<json_value>::value
);
void swap(reference left, reference right) noexcept;
// (3)
void swap(array_t& other);
@@ -66,15 +56,15 @@ void swap(typename binary_t::container_type& other);
1. No-throw guarantee: this function never throws exceptions.
2. No-throw guarantee: this function never throws exceptions.
3. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
arrays; example: `"cannot use swap(array_t&) with boolean"`
arrays; example: `"cannot use swap() with boolean"`
4. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
objects; example: `"cannot use swap(object_t&) with boolean"`
objects; example: `"cannot use swap() with boolean"`
5. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
strings; example: `"cannot use swap(string_t&) with boolean"`
strings; example: `"cannot use swap() with boolean"`
6. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
binaries; example: `"cannot use swap(binary_t&) with boolean"`
binaries; example: `"cannot use swap() with boolean"`
7. Throws [`type_error.310`](../../home/exceptions.md#jsonexceptiontype_error310) if called on JSON values other than
binaries; example: `"cannot use swap(binary_t::container_type&) with boolean"`
binaries; example: `"cannot use swap() with boolean"`
## Complexity
@@ -138,7 +128,7 @@ Constant.
--8<-- "examples/swap__string_t.output"
```
??? example "Example: Swap binary (6)"
??? example "Example: Swap string (6)"
The example below shows how binary values can be swapped with `swap()`.
@@ -155,8 +145,6 @@ Constant.
## See also
- [std::swap<basic_json\>](std_swap.md)
- [operator=](operator=.md) copy assignment
- [basic_json](basic_json.md) create a JSON value
## Version history
@@ -72,14 +72,6 @@ Linear in the size of the JSON value `j`.
--8<-- "examples/to_bjdata.output"
```
## See also
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
- [to_bson](to_bson.md) create a BSON serialization of a JSON value
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
## Version history
- Added in version 3.11.0.
@@ -34,13 +34,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Exceptions
- Throws [`type_error.317`](../../home/exceptions.md#jsonexceptiontype_error317) if the top-level type of the JSON value
is not an object; example: `"to serialize to BSON, top-level type must be object, but is string"`
- Throws [`out_of_range.409`](../../home/exceptions.md#jsonexceptionout_of_range409) if a key in the JSON object contains
a null byte (code point U+0000); example: `"BSON key cannot contain code point U+0000 (at byte 2)"`
## Complexity
Linear in the size of the JSON value `j`.
@@ -61,14 +54,6 @@ Linear in the size of the JSON value `j`.
--8<-- "examples/to_bson.output"
```
## See also
- [from_bson](from_bson.md) create a JSON value from an input in BSON format
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
## Version history
- Added in version 3.4.0.
@@ -55,14 +55,6 @@ Linear in the size of the JSON value `j`.
--8<-- "examples/to_cbor.output"
```
## See also
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
- [to_bson](to_bson.md) create a BSON serialization of a JSON value
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
## Version history
- Added in version 2.0.9.
@@ -54,14 +54,6 @@ Linear in the size of the JSON value `j`.
--8<-- "examples/to_msgpack.output"
```
## See also
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
- [to_bson](to_bson.md) create a BSON serialization of a JSON value
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
## Version history
- Added in version 2.0.9.
@@ -65,14 +65,6 @@ Linear in the size of the JSON value `j`.
--8<-- "examples/to_ubjson.output"
```
## See also
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value
- [to_bson](to_bson.md) create a BSON serialization of a JSON value
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value
## Version history
- Added in version 3.1.0.
@@ -67,7 +67,6 @@ classDiagram
## See also
- [`exception`](exception.md) for the base class of all exceptions thrown by the library
- [List of type errors](../../home/exceptions.md#type-errors)
- [`parse_error`](parse_error.md) for exceptions indicating a parse error
- [`invalid_iterator`](invalid_iterator.md) for exceptions indicating errors with iterators
@@ -25,10 +25,6 @@ The function can throw the following exceptions:
- Throws [`type_error.314`](../../home/exceptions.md#jsonexceptiontype_error314) if value is not an object
- Throws [`type_error.315`](../../home/exceptions.md#jsonexceptiontype_error315) if object values are not primitive
- Throws [`type_error.313`](../../home/exceptions.md#jsonexceptiontype_error313) if a key (JSON pointer) leads to a
conflicting nesting; example: `"invalid value to unflatten"`
- Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) if an array index in a key is not a
number; example: `"array index 'one' is not a number"`
## Complexity
+4 -13
View File
@@ -14,8 +14,6 @@ void update(const_iterator first, const_iterator last, bool merge_objects = fals
When `merge_objects` is `#!c false` (default), existing keys are overwritten. When `merge_objects` is `#!c true`,
recursively merges objects with common keys.
If the JSON value is `#!json null`, it is implicitly converted to an empty object before the values are inserted.
The function is motivated by Python's [dict.update](https://docs.python.org/3.6/library/stdtypes.html#dict.update)
function.
@@ -30,8 +28,8 @@ iterators (including the `end()` iterator) and all references to the elements ar
: JSON object to read values from
`merge_objects` (in)
: when `#!c true`, keys that exist in both objects and whose value in the source is itself an object are merged
recursively; all other values are overwritten as usual (default: `#!c false`)
: when `#!c true`, existing keys are not overwritten, but contents of objects are merged recursively (default:
`#!c false`)
`first` (in)
: the beginning of the range of elements to insert
@@ -39,10 +37,6 @@ iterators (including the `end()` iterator) and all references to the elements ar
`last` (in)
: the end of the range of elements to insert
## Exception safety
Basic guarantee: if an exception is thrown during the operation, the JSON value may be partially modified.
## Exceptions
1. The function can throw the following exceptions:
@@ -51,6 +45,8 @@ Basic guarantee: if an exception is thrown during the operation, the JSON value
2. The function can throw the following exceptions:
- Throws [`type_error.312`](../../home/exceptions.md#jsonexceptiontype_error312) if called on JSON values other than
objects; example: `"cannot use update() with string"`
- Throws [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202) if called on an
iterator which does not belong to the current JSON value; example: `"iterator does not fit current value"`
- Throws [`invalid_iterator.210`](../../home/exceptions.md#jsonexceptioninvalid_iterator210) if `first` and `last`
do not belong to the same JSON value; example: `"iterators do not fit"`
@@ -145,11 +141,6 @@ Basic guarantee: if an exception is thrown during the operation, the JSON value
}
```
## See also
- [insert](insert.md) add values to an array/object
- [merge_patch](merge_patch.md) applies a JSON Merge Patch
## Version history
- Added in version 3.0.0.
+1 -1
View File
@@ -95,7 +95,7 @@ changes to any JSON value.
- Throws [`type_error.302`](../../home/exceptions.md#jsonexceptiontype_error302) if `default_value` does not match
the type of the value at `ptr`
- Throws [`type_error.306`](../../home/exceptions.md#jsonexceptiontype_error306) if the JSON value is not an object;
in that case, using `value()` with a JSON pointer makes no sense.
in that case, using `value()` with a key makes no sense.
## Complexity
@@ -24,7 +24,7 @@ specific naming scheme in order to override the binary type.
- [(constructor)](byte_container_with_subtype.md)
- **operator==** - comparison: equal
- **operator!=** - comparison: not equal
- [**set_subtype**](set_subtype.md) - sets the binary subtype
- [**set_subtype**](subtype.md) - sets the binary subtype
- [**subtype**](subtype.md) - return the binary subtype
- [**has_subtype**](has_subtype.md) - return whether the value has a subtype
- [**clear_subtype**](clear_subtype.md) - clears the binary subtype
@@ -35,5 +35,3 @@ Constant.
```
## Version history
- Added in version 3.12.x.
@@ -10,10 +10,6 @@ Returns the parent of this JSON pointer.
Parent of this JSON pointer; in case this JSON pointer is the root, the root itself is returned.
## Exception safety
No-throw guarantee: this function never throws exceptions.
## Complexity
Linear in the length of the JSON pointer.
@@ -34,11 +30,6 @@ Linear in the length of the JSON pointer.
--8<-- "examples/json_pointer__parent_pointer.output"
```
## See also
- [pop_back](pop_back.md) remove the last reference token
- [back](back.md) return the last reference token
## Version history
Added in version 3.6.0.
@@ -31,5 +31,3 @@ Linear in the number of reference tokens in the `json_pointer`.
```
## Version history
- Added in version 3.12.x.
@@ -34,5 +34,3 @@ Linear in the number of reference tokens in the `json_pointer`.
```
## Version history
- Added in version 3.12.x.
+1 -1
View File
@@ -9,7 +9,7 @@ The beginning of an array was read.
## Parameters
`elements` (in)
: number of array elements, or `#!cpp std::numeric_limits<std::size_t>::max()` if unknown
: number of object elements or `#!cpp -1` if unknown
## Return value
@@ -9,7 +9,7 @@ The beginning of an object was read.
## Parameters
`elements` (in)
: number of object elements, or `#!cpp std::numeric_limits<std::size_t>::max()` if unknown
: number of object elements or `#!cpp -1` if unknown
## Return value
@@ -92,4 +92,4 @@ The default value is `0` (disabled — existing behavior is preserved).
## Version history
- Added in version 3.12.x.
- Added in version 3.12.0.
@@ -122,13 +122,14 @@ The default value is `0`.
void to_json(json& j, const Choice& ch)
{
if (ch == Choice::first)
auto value = j.get<std::string>();
if (value == "first")
{
j = "first";
ch = Choice::first;
}
else if (ch == Choice::second)
else if (value == "second")
{
j = "second";
ch = Choice::second;
}
}
@@ -1,12 +1,10 @@
# 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, JSON_HAS_CPP_14, JSON_HAS_CPP_17, JSON_HAS_CPP_20
```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`
@@ -22,9 +20,7 @@ The default value is detected based on preprocessor macros such as `#!cpp __cplu
## Notes
- 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.
- `#!cpp JSON_HAS_CPP_11` is always defined.
- All macros are undefined outside the library.
## Examples
@@ -43,5 +39,3 @@ 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 libstdc++ also require the library `stdc++fs` to be linked to for
- Note that older compilers or older versions of libstd++ also require the library `stdc++fs` to be linked to for
filesystem support.
- Both macros are undefined outside the library.
@@ -24,17 +24,6 @@ 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_legacydiscardedvaluecomparison)
[`JSON_LegacyDiscardedValueComparison`](../../integration/cmake.md#json_implicitconversions)
(`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 serialization | Allow missing values when de-serializing | macro |
| Need access to private members | Need only de-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_TYPE_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_intrusive.md)
NLOHMANN_DEFINE_DERIVED_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_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE](nlohmann_define_type_non_intrusive.md)
NLOHMANN_DEFINE_DERIVED_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 serialization | Allow missing values when de-serializing | macro |
| Need access to private members | Need only de-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 serialization | Allow missing values when de-serializing | macro |
| Need access to private members | Need only de-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.12.x.
1. Added in version 3.11.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_12_0
inline namespace json_abi_v3_11_2
{
```
2. Default definition of `NLOHMANN_JSON_NAMESPACE_END`:
```cpp
} // namespace json_abi_v3_12_0
} // namespace json_abi_v3_11_2
} // namespace nlohmann
```
@@ -38,10 +38,7 @@ inline void from_json(const BasicJsonType& j, type& e);
!!! important "Important notes"
- 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>"`.
- When using [`get<ENUM_TYPE>()`](../basic_json/get.md), undefined JSON values will throw an exception.
- 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.
@@ -102,4 +99,4 @@ inline void from_json(const BasicJsonType& j, type& e);
## Version history
Added in version 3.12.x.
Added in version 3.12.0.
+3 -4
View File
@@ -21,6 +21,8 @@ the stream `i`
## Exceptions
- Throws [`parse_error.101`](../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token.
- Throws [`parse_error.102`](../home/exceptions.md#jsonexceptionparse_error102) if `to_unicode` fails or surrogate error.
- Throws [`parse_error.103`](../home/exceptions.md#jsonexceptionparse_error103) if `to_unicode` fails.
## Complexity
@@ -30,9 +32,6 @@ Linear in the length of the input. The parser is a predictive LL(1) parser.
A UTF-8 byte order mark is silently ignored.
Invalid Unicode escapes and unpaired surrogates in the input are reported as
[`parse_error.101`](../home/exceptions.md#jsonexceptionparse_error101) with a detailed message.
!!! warning "Deprecation"
This function replaces function `#!cpp std::istream& operator<<(basic_json& j, std::istream& i)` which has
@@ -62,4 +61,4 @@ Invalid Unicode escapes and unpaired surrogates in the input are reported as
## Version history
- Added in version 1.0.0.
- Added in version 1.0.0. Deprecated in version 3.0.0.
@@ -60,4 +60,4 @@ Linear.
- Added in version 1.0.0.
- Moved to namespace `nlohmann::literals::json_literals` in 3.11.0.
- Added `char8_t*` overload in 3.12.x.
- Added `char8_t*` overload in 3.12.1.
@@ -63,4 +63,4 @@ Linear.
- Added in version 2.0.0.
- Moved to namespace `nlohmann::literals::json_literals` in 3.11.0.
- Added `char8_t*` overload in 3.12.x.
- Added `char8_t*` overload in 3.12.1.
@@ -82,11 +82,16 @@ violations will result in a failed build.
| GNU 14.2.0 | arm64 | Linux 6.1.100 | Cirrus CI |
| GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
| icpc (ICC) 2021.5.0 20211109 | x86_64 | Ubuntu 20.04.3 LTS | GitHub |
| icpx (Intel oneAPI DPC++/C++) 2025.3.2 | x86_64 | Ubuntu 24.04 LTS | GitHub |
| nvc++ (NVIDIA HPC SDK) 25.5-0 | x86_64 | Ubuntu 22.04 LTS | GitHub |
| MSVC 19.0.24241.7 | x86 | Windows 8.1 | AppVeyor |
| MSVC 19.16.27035.0 | x86 | Windows-10 (Build 14393) | AppVeyor |
| MSVC 19.29.30157.0 | x86 | Windows-10 (Build 17763) | AppVeyor |
| MSVC 19.44.35207.0 | arm64 | Windows 11 (Build 26200) | GitHub |
| MSVC 19.44.35214.0 | x86 | Windows Server 2022 (Build 20348) | GitHub |
| MSVC 19.44.35214.0 | x86_64 | Windows Server 2022 (Build 20348) | GitHub |
| MSVC 19.51.36231.0 | x86 | Windows Server 2025 (Build 26100) | GitHub |
| MSVC 19.51.36231.0 | x86_64 | Windows Server 2025 (Build 26100) | GitHub |
- [x] The library is compiled with all C++ language revisions (C++11, C++14, C++17, C++20, C++23, and C++26) to detect
and fix language deprecations early.
+1 -1
View File
@@ -27,7 +27,7 @@ For more information, see [JSON With Commas and Comments (JWCC)](https://nigelta
}
```
When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_comments` is set to `#!cpp true`, the comments are ignored during parsing:
When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_comments` is set to `#! true`, the comments are ignored during parsing:
```cpp
--8<-- "examples/comments.cpp"
+2 -41
View File
@@ -9,14 +9,6 @@ This macro controls which code is executed for [runtime assertions](assertions.m
See [full documentation of `JSON_ASSERT(x)`](../api/macros/json_assert.md).
## `JSON_BRACE_INIT_COPY_SEMANTICS`
When defined to `1`, single-element brace initialization of a `basic_json` value (e.g., `#!cpp json j{value};`) is
treated as a copy/move of the element rather than wrapping it in a single-element array. The default value is `0`, which
preserves the existing behavior.
See [full documentation of `JSON_BRACE_INIT_COPY_SEMANTICS`](../api/macros/json_brace_init_copy_semantics.md).
## `JSON_CATCH_USER(exception)`
This macro overrides [`#!cpp catch`](https://en.cppreference.com/w/cpp/language/try_catch) calls inside the library.
@@ -52,7 +44,7 @@ The diagnostics positions can also be controlled with the CMake option
See [full documentation of `JSON_DIAGNOSTIC_POSITIONS`](../api/macros/json_diagnostic_positions.md)
## `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`, `JSON_HAS_CPP_14`, `JSON_HAS_CPP_17`, `JSON_HAS_CPP_20`
The library targets C++11, but also supports some features introduced in later C++ versions (e.g., `std::string_view`
support for C++17). For these new features, the library implements some preprocessor checks to determine the C++
@@ -60,7 +52,7 @@ standard. By defining any of these symbols, the internal check is overridden and
unconditionally assumed. This can be helpful for compilers that only implement parts of the standard and would be
detected incorrectly.
See [full documentation of `JSON_HAS_CPP_11`, `JSON_HAS_CPP_14`, `JSON_HAS_CPP_17`, `JSON_HAS_CPP_20`, `JSON_HAS_CPP_23`, and `JSON_HAS_CPP_26`](../api/macros/json_has_cpp_11.md).
See [full documentation of `JSON_HAS_CPP_11`, `JSON_HAS_CPP_14`, `JSON_HAS_CPP_17`, and `JSON_HAS_CPP_20`](../api/macros/json_has_cpp_11.md).
## `JSON_HAS_FILESYSTEM`, `JSON_HAS_EXPERIMENTAL_FILESYSTEM`
@@ -123,39 +115,11 @@ When defined to `0`, implicit conversions are switched off. By default, implicit
See [full documentation of `JSON_USE_IMPLICIT_CONVERSIONS`](../api/macros/json_use_implicit_conversions.md).
## `JSON_USE_GLOBAL_UDLS`
When defined to `1` (default), the user-defined string literals `operator""_json` and `operator""_json_pointer` are
placed into the global namespace instead of `nlohmann::literals::json_literals`.
See [full documentation of `JSON_USE_GLOBAL_UDLS`](../api/macros/json_use_global_udls.md).
## `JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON`
When defined to `1`, the library restores the legacy behavior in which a discarded value compared equal to itself. This
behavior is deprecated and switched off (`0`) by default.
See [full documentation of `JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON`](../api/macros/json_use_legacy_discarded_value_comparison.md).
## `NLOHMANN_DEFINE_TYPE_*(...)`, `NLOHMANN_DEFINE_DERIVED_TYPE_*(...)`
The library defines 12 macros to simplify the serialization/deserialization of types. See the page on
[arbitrary type conversion](arbitrary_types.md#simplify-your-life-with-macros) for a detailed discussion.
## `NLOHMANN_JSON_NAMESPACE`, `NLOHMANN_JSON_NAMESPACE_BEGIN`, `NLOHMANN_JSON_NAMESPACE_END`, `NLOHMANN_JSON_NAMESPACE_NO_VERSION`
These macros relate to the versioned, inline `nlohmann` namespace:
- `NLOHMANN_JSON_NAMESPACE` evaluates to the full name of the `nlohmann` namespace (including the inline ABI namespace).
- `NLOHMANN_JSON_NAMESPACE_BEGIN` / `NLOHMANN_JSON_NAMESPACE_END` open and close the namespace (for example, to add
specializations).
- `NLOHMANN_JSON_NAMESPACE_NO_VERSION`, when defined to `1`, omits the version component from the inline namespace.
See the [`nlohmann` Namespace](namespace.md) page, and the full documentation of
[`NLOHMANN_JSON_NAMESPACE`](../api/macros/nlohmann_json_namespace.md),
[`NLOHMANN_JSON_NAMESPACE_BEGIN` / `NLOHMANN_JSON_NAMESPACE_END`](../api/macros/nlohmann_json_namespace_begin.md), and
[`NLOHMANN_JSON_NAMESPACE_NO_VERSION`](../api/macros/nlohmann_json_namespace_no_version.md).
## `NLOHMANN_JSON_SERIALIZE_ENUM(type, ...)`
This macro simplifies the serialization/deserialization of enum types. See
@@ -163,9 +127,6 @@ This macro simplifies the serialization/deserialization of enum types. See
See [full documentation of `NLOHMANN_JSON_SERIALIZE_ENUM`](../api/macros/nlohmann_json_serialize_enum.md).
A strict variant [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../api/macros/nlohmann_json_serialize_enum_strict.md) throws an
exception on undefined input instead of falling back to the first mapping.
## `NLOHMANN_JSON_VERSION_MAJOR`, `NLOHMANN_JSON_VERSION_MINOR`, `NLOHMANN_JSON_VERSION_PATCH`
These macros are defined by the library and contain the version numbers according to
+1 -1
View File
@@ -10,7 +10,7 @@ The default type `nlohmann::json` uses a `std::map` to store JSON objects, and t
```cpp
#include <iostream>
#include <nlohmann/json.hpp>
#include "json.hpp"
using json = nlohmann::json;
@@ -70,7 +70,7 @@ The return value indicates whether the parsing should continue, so the function
```cpp
#include <iostream>
#include <nlohmann/json.hpp>
#include "json.hpp"
using json = nlohmann::json;
+1 -1
View File
@@ -26,7 +26,7 @@ For more information, see [JSON With Commas and Comments (JWCC)](https://nigelta
}
```
When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_trailing_commas` is set to `#!cpp true`, the trailing commas are ignored during parsing:
When calling `parse` without additional argument, a parse error exception is thrown. If `ignore_trailing_commas` is set to `#! true`, the trailing commas are ignored during parsing:
```cpp
--8<-- "examples/trailing_commas.cpp"
+1 -4
View File
@@ -870,15 +870,12 @@ Key identifiers to be serialized to BSON cannot contain code point U+0000, since
### json.exception.out_of_range.410
This exception is thrown when an undefined value is used with
[`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../api/macros/nlohmann_json_serialize_enum_strict.md), or when an array index in
a JSON pointer exceeds the range of `size_type` (e.g., on 32-bit platforms).
Undefined json fields cannot be used with [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../api/macros/nlohmann_json_serialize_enum_strict.md)
!!! failure "Example message"
```
enum value out of range
array index 18446744073709551616 exceeds size_type
```
## Further exceptions
File diff suppressed because it is too large Load Diff
+1 -6
View File
@@ -167,7 +167,7 @@ Enable the (incorrect) legacy comparison behavior of discarded JSON values by de
### `JSON_MultipleHeaders`
Use the non-amalgamated version of the library. This option is `ON` by default.
Use the non-amalgamated version of the library. This option is `OFF` by default.
### `JSON_SystemInclude`
@@ -176,8 +176,3 @@ Treat the library headers like system headers (i.e., adding `SYSTEM` to the [`ta
### `JSON_Valgrind`
Execute the test suite with [Valgrind](https://valgrind.org). This option is `OFF` by default. Depends on `JSON_BuildTests`.
### `NLOHMANN_JSON_BUILD_MODULES`
Build the experimental [C++ module](../features/modules.md) `nlohmann.json` (requires CMake 3.28 or later and C++20).
This option is `OFF` by default.
@@ -198,6 +198,10 @@ conversions with calls to [`get`](../api/basic_json/get.md), [`get_to`](../api/b
j.get_to(s);
```
You can prepare existing code by already defining
[`JSON_USE_IMPLICIT_CONVERSIONS`](../api/macros/json_use_implicit_conversions.md) to `0` and replace any implicit
conversions with calls to [`get`](../api/basic_json/get.md).
## Import namespace `literals` for UDLs
The user-defined string literals [`operator""_json`](../api/operator_literal_json.md) and
@@ -13,7 +13,7 @@
![Nuget](../images/package_managers/nuget.svg){: style="height:1em"}&nbsp;[**NuGet**](#nuget) `nlohmann.json` &emsp;
![Conda](../images/package_managers/conda.svg){: style="height:1em"}&nbsp;[**Conda**](#conda) `nlohmann_json` &emsp;
![MacPorts](../images/package_managers/macports.svg){: style="height:1em"}&nbsp;[**MacPorts**](#macports) `nlohmann-json`<br>
![cpm.cmake](../images/package_managers/CPM.png){: style="height:1em"}&nbsp;[**CPM.cmake**](#cpmcmake) `gh:nlohmann/json` &emsp;
![cpm.cmake](../images/package_managers/CPM.png){: style="height:1em"}&nbsp;[**CPM.cmake**](#cpmcmake) `gh:nlohmann/json`
![xmake](../images/package_managers/xmake.svg){: style="height:1em"}&nbsp;[**xmake**](#xmake) `nlohmann_json`
</p>
@@ -105,7 +105,7 @@ The header can be used directly in your code or via CMake.
- :octicons-tag-24: Available versions: current version and select older versions (see
[WrapDB](https://mesonbuild.com/Wrapdb-projects.html))
- :octicons-rocket-24: The package is updated automatically from file
- :octicons-rocket-24: The package is update automatically from file
[`meson.build`](https://github.com/nlohmann/json/blob/develop/meson.build).
- :octicons-file-24: File issues at the [library issue tracker](https://github.com/nlohmann/json/issues)
- :octicons-question-24: [Meson website](https://mesonbuild.com/index.html)
@@ -197,7 +197,7 @@ repository can be referenced within a `MODULE.bazel` by rules such as `archive_o
- [![ConanCenter package](https://repology.org/badge/version-for-repo/conancenter/nlohmann-json.svg)](https://repology.org/project/nlohmann-json/versions)
- :octicons-tag-24: Available versions: current version and older versions (see
[Conan Center](https://conan.io/center/recipes/nlohmann_json))
- :octicons-rocket-24: The package is updated automatically via
- :octicons-rocket-24: The package is update automatically via
[this recipe](https://github.com/conan-io/conan-center-index/tree/master/recipes/nlohmann_json).
- :octicons-file-24: File issues at the [Conan Center issue tracker](https://github.com/conan-io/conan-center-index/issues)
- :octicons-question-24: [Conan website](https://conan.io)
@@ -603,7 +603,7 @@ conda install -c conda-forge nlohmann_json
--8<-- "integration/conda/example.cpp"
```
2. Create and activate an environment `json`:
2. Create and activate an anvironment "json`:
```shell
conda create -n json
@@ -667,7 +667,7 @@ to install the [nlohmann-json](https://ports.macports.org/port/nlohmann-json/) p
sudo port install nlohmann-json
```
3. Compile the code and pass the MacPorts prefix to the include path such that the library can be found:
3. Compile the code and pass the Homebrew prefix to the include path such that the library can be found:
```sh
c++ example.cpp -I/opt/local/include -std=c++11 -o example
@@ -709,17 +709,17 @@ to install the [nlohmann-json](https://ports.macports.org/port/nlohmann-json/) p
- [package's sources (for advanced users)](https://github.com/build2-packaging/nlohmann-json/)
- :octicons-tag-24: Available versions: current version and older versions since `3.7.3` (see [cppget.org](https://cppget.org/nlohmann-json))
- :octicons-rocket-24: The package is maintained and published by the `build2` community in [this repository](https://github.com/build2-packaging/nlohmann-json/).
- :octicons-rocket-24: The package is maintained and published by the `build2` community in [this repository][(https://github.com/build2-packaging/nlohmann-json/](https://github.com/build2-packaging/nlohmann-json/)).
- :octicons-file-24: File issues at the [package source repository](https://github.com/build2-packaging/nlohmann-json/issues/)
- :octicons-question-24: [`build2` website](https://build2.org)
- :octicons-question-24: [`build2` website](https://build2)
Note: [`build2`](https://build2.org) should not be considered as a standalone package-manager. It is a build-system + package manager + project manager, a set of tools that work hand-in-hand. `build2`-based projects do not rely on existing `CMake` scripts and the build scripts defining the project's targets are specific to `build2`.
To use this package in an existing [`build2`](https://build2.org) project, the general steps are:
To use this package in an exising [`build2`](https://build2.org) project, the general steps are:
1. <details><summary>Make the package available to download from a package repository that provides it.</summary>
Your project's `repositories.manifest` specifies where the package manager will try to acquire packages by default. Make sure one of the repositories specified in this file provides `nlohmann-json` package.
Your project's `repositories.manifest` specifies where the package manager will try to acquire packages by default. Make sure one of the repositories specified in this file provides `nlhomann-json` package.
The recommended open-source repository is [`cppget.org`](https://cppget.org/).
If the project has been created using [`bdep new`](https://build2.org/bdep/doc/bdep-new.xhtml), `cppget.org` is already specified in `repositories.manifest` but commented, just uncomment these lines:
@@ -740,13 +740,13 @@ To use this package in an existing [`build2`](https://build2.org) project, the g
</details>
3. <details><summary>Add this library as dependency of your target that uses it.</summary>
2. <details><summary>Add this library as dependency of your target that uses it.</summary>
In the `buildfile` defining the target that will use this library:
- import the target `lib{json}` from the `nlohmann-json` package, for example:
- import the target `lib{json}` from the `nlhomann-json` package, for example:
```
import nljson = nlohmann-json%lib{json}
import nljson = nlhomann-json%lib{json}
```
- then add the library's target as requirement for your target using it, for example:
@@ -756,7 +756,7 @@ To use this package in an existing [`build2`](https://build2.org) project, the g
</details>
4. <details><summary>Use the library in your project's code and build it.</summary>
3. <details><summary>Use the library in your project's code and build it.</summary>
At this point, assuming your project is initialized in a build-configuration, any `b` or `bdep update` command that will update/build the project will also acquire the missing dependency automatically, then build it and link it with your target.
@@ -818,7 +818,7 @@ To use this package in an existing [`build2`](https://build2.org) project, the g
# build only,
b
# or build and test the executable's output, will only work if the `testscript` is correct
# or build and test the executable's output, will only work if the `tescript` is correct
b test
```
+3 -3
View File
@@ -88,9 +88,9 @@ class parser
@param[in] strict whether to expect the last token to be EOF
@param[in,out] result parsed JSON value
@throw parse_error.101 in case of an unexpected token (including invalid
unicode escapes and surrogate errors, which are reported with a
detailed message)
@throw parse_error.101 in case of an unexpected token
@throw parse_error.102 if to_unicode fails or surrogate error
@throw parse_error.103 if to_unicode fails
*/
void parse(const bool strict, BasicJsonType& result)
{
-9
View File
@@ -137,15 +137,6 @@
// ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error
#if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
#define JSON_HAS_RANGES 0
// libstdc++ < 11 has incomplete C++20 ranges (issue #4440)
#elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11
#define JSON_HAS_RANGES 0
// libc++ < 16 has incomplete C++20 ranges (issue #4440)
#elif defined(__clang__) && !defined(__apple_build_version__) \
&& __clang_major__ < 16 && defined(__GLIBCXX__)
#define JSON_HAS_RANGES 0
#elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000
#define JSON_HAS_RANGES 0
#elif defined(__cpp_lib_ranges)
#define JSON_HAS_RANGES 1
#else
@@ -881,7 +881,7 @@ class binary_writer
for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
{
oa->write_character(to_char_type(bjdata_draft3 ? 'B' : 'U'));
oa->write_character(to_char_type(j.m_data.m_value.binary->data()[i]));
oa->write_character(j.m_data.m_value.binary->data()[i]);
}
}
@@ -1634,9 +1634,7 @@ class binary_writer
};
string_t key = "_ArrayType_";
// use get<string_t>() instead of static_cast<string_t> to avoid an
// ambiguous conversion under explicit instantiation on C++17 (see #4825)
auto it = bjdtype.find(value.at(key).template get<string_t>());
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
if (it == bjdtype.end())
{
return true;
+2 -2
View File
@@ -400,7 +400,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
};
std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
JSON_ASSERT(obj);
JSON_ASSERT(obj != nullptr);
return obj.release();
}
@@ -4280,7 +4280,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
};
data m_data = {}; // NOLINT(readability-redundant-member-init)
data m_data = {};
#if JSON_DIAGNOSTICS
/// a pointer to a parent value (for debugging purposes)
+7 -18
View File
@@ -2511,15 +2511,6 @@ JSON_HEDLEY_DIAGNOSTIC_POP
// ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error
#if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
#define JSON_HAS_RANGES 0
// libstdc++ < 11 has incomplete C++20 ranges (issue #4440)
#elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11
#define JSON_HAS_RANGES 0
// libc++ < 16 has incomplete C++20 ranges (issue #4440)
#elif defined(__clang__) && !defined(__apple_build_version__) \
&& __clang_major__ < 16 && defined(__GLIBCXX__)
#define JSON_HAS_RANGES 0
#elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000
#define JSON_HAS_RANGES 0
#elif defined(__cpp_lib_ranges)
#define JSON_HAS_RANGES 1
#else
@@ -13346,9 +13337,9 @@ class parser
@param[in] strict whether to expect the last token to be EOF
@param[in,out] result parsed JSON value
@throw parse_error.101 in case of an unexpected token (including invalid
unicode escapes and surrogate errors, which are reported with a
detailed message)
@throw parse_error.101 in case of an unexpected token
@throw parse_error.102 if to_unicode fails or surrogate error
@throw parse_error.103 if to_unicode fails
*/
void parse(const bool strict, BasicJsonType& result)
{
@@ -17076,7 +17067,7 @@ class binary_writer
for (size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
{
oa->write_character(to_char_type(bjdata_draft3 ? 'B' : 'U'));
oa->write_character(to_char_type(j.m_data.m_value.binary->data()[i]));
oa->write_character(j.m_data.m_value.binary->data()[i]);
}
}
@@ -17829,9 +17820,7 @@ class binary_writer
};
string_t key = "_ArrayType_";
// use get<string_t>() instead of static_cast<string_t> to avoid an
// ambiguous conversion under explicit instantiation on C++17 (see #4825)
auto it = bjdtype.find(value.at(key).template get<string_t>());
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
if (it == bjdtype.end())
{
return true;
@@ -20920,7 +20909,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
};
std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
JSON_ASSERT(obj);
JSON_ASSERT(obj != nullptr);
return obj.release();
}
@@ -24800,7 +24789,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
};
data m_data = {}; // NOLINT(readability-redundant-member-init)
data m_data = {};
#if JSON_DIAGNOSTICS
/// a pointer to a parent value (for debugging purposes)

Some files were not shown because too many files have changed in this diff Show More