mirror of
https://github.com/nlohmann/json.git
synced 2026-06-19 02:44:20 +00:00
Overwork documentation (#4516)
This commit is contained in:
@@ -29,9 +29,9 @@ Unlike the [`parse`](parse.md) function, this function neither throws an excepti
|
||||
: A compatible input, for instance:
|
||||
|
||||
- an `std::istream` object
|
||||
- a `FILE` pointer (must not be null)
|
||||
- a `FILE` pointer (throws if null)
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters
|
||||
- a pointer to a null-terminated string of single byte characters (throws if null)
|
||||
- a `std::string`
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
@@ -64,18 +64,17 @@ Whether the input is valid JSON.
|
||||
|
||||
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
|
||||
|
||||
## Exceptions
|
||||
|
||||
Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an empty input like a null `FILE*` or `char*` pointer.
|
||||
|
||||
## Complexity
|
||||
|
||||
Linear in the length of the input. The parser is a predictive LL(1) parser.
|
||||
|
||||
## Notes
|
||||
|
||||
(1) A UTF-8 byte order mark is silently ignored.
|
||||
|
||||
!!! danger "Runtime assertion"
|
||||
|
||||
The precondition that a passed `#!cpp FILE` pointer must not be null is enforced with a
|
||||
[runtime assertion](../../features/assertions.md).
|
||||
A UTF-8 byte order mark is silently ignored.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -102,6 +101,7 @@ Linear in the length of the input. The parser is a predictive LL(1) parser.
|
||||
|
||||
- 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.11.4.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ created from `args`.
|
||||
`Args`
|
||||
: compatible types to create a `basic_json` object
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
For [`ordered_json`](../ordered_json.md), adding a value to an object can yield a reallocation, in which case all
|
||||
iterators (including the `end()` iterator) and all references to the elements are invalidated.
|
||||
|
||||
## Parameters
|
||||
|
||||
`args` (in)
|
||||
|
||||
@@ -13,6 +13,12 @@ Creates a JSON value from the passed parameters `args` to the end of the JSON va
|
||||
`Args`
|
||||
: compatible types to create a `basic_json` object
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
By adding an element to the end of the array, a reallocation can happen, in which case all iterators (including the
|
||||
[`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the [`end()`](end.md)
|
||||
iterator is invalidated.
|
||||
|
||||
## Parameters
|
||||
|
||||
`args` (in)
|
||||
@@ -48,6 +54,11 @@ Amortized constant.
|
||||
--8<-- "examples/emplace_back.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [operator+=](operator+=.md) add a value to an array/object
|
||||
- [push_back](push_back.md) add a value to an array/object
|
||||
|
||||
## Version history
|
||||
|
||||
- Since version 2.0.8.
|
||||
|
||||
@@ -8,24 +8,36 @@ This class is an extension of [`std::exception`](https://en.cppreference.com/w/c
|
||||
member `id` for exception ids. It is used as the base class for all exceptions thrown by the `basic_json` class. This
|
||||
class can hence be used as "wildcard" to catch exceptions, see example below.
|
||||
|
||||
```plantuml
|
||||
std::exception <|-- basic_json::exception
|
||||
basic_json::exception <|-- basic_json::parse_error
|
||||
basic_json::exception <|-- basic_json::invalid_iterator
|
||||
basic_json::exception <|-- basic_json::type_error
|
||||
basic_json::exception <|-- basic_json::out_of_range
|
||||
basic_json::exception <|-- basic_json::other_error
|
||||
```mermaid
|
||||
classDiagram
|
||||
direction LR
|
||||
|
||||
class std_exception ["std::exception"] {
|
||||
<<interface>>
|
||||
}
|
||||
|
||||
interface std::exception {}
|
||||
class json_exception ["basic_json::exception"] {
|
||||
+const int id
|
||||
+const char* what() const
|
||||
}
|
||||
|
||||
class json_parse_error ["basic_json::parse_error"] {
|
||||
+const std::size_t byte
|
||||
}
|
||||
|
||||
class basic_json::exception #FFFF00 {
|
||||
+ const int id
|
||||
+ const char* what() const
|
||||
}
|
||||
class json_invalid_iterator ["basic_json::invalid_iterator"]
|
||||
class json_type_error ["basic_json::type_error"]
|
||||
class json_out_of_range ["basic_json::out_of_range"]
|
||||
class json_other_error ["basic_json::other_error"]
|
||||
|
||||
class basic_json::parse_error {
|
||||
+ const std::size_t byte
|
||||
}
|
||||
std_exception <|-- json_exception
|
||||
json_exception <|-- json_parse_error
|
||||
json_exception <|-- json_invalid_iterator
|
||||
json_exception <|-- json_type_error
|
||||
json_exception <|-- json_out_of_range
|
||||
json_exception <|-- json_other_error
|
||||
|
||||
style json_exception fill:#CCCCFF
|
||||
```
|
||||
|
||||
Subclasses:
|
||||
|
||||
@@ -37,7 +37,9 @@ Constant.
|
||||
|
||||
The pointer becomes invalid if the underlying JSON object changes.
|
||||
|
||||
Consider the following example code where the pointer `ptr` changes after the array is resized. As a result, reading or writing to `ptr` after the array change would be undefined behavior. The address of the first array element changes, because the underlying `std::vector` is resized after adding a fifth element.
|
||||
Consider the following example code where the pointer `ptr` changes after the array is resized. As a result,
|
||||
reading or writing to `ptr` after the array change would be undefined behavior. The address of the first array
|
||||
element changes, because the underlying `std::vector` is resized after adding a fifth element.
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
|
||||
@@ -42,7 +42,15 @@ class basic_json;
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
Todo
|
||||
All operations that add values to an **array** ([`push_back`](push_back.md) , [`operator+=`](operator+=.md),
|
||||
[`emplace_back`](emplace_back.md), [`insert`](insert.md), and [`operator[]`](operator%5B%5D.md) for a non-existing
|
||||
index) can yield a reallocation, in which case all iterators (including the [`end()`](end.md) iterator) and all
|
||||
references to the elements are invalidated.
|
||||
|
||||
For [`ordered_json`](../ordered_json.md), also all operations that add a value to an **object**
|
||||
([`push_back`](push_back.md), [`operator+=`](operator+=.md), [`emplace`](emplace.md), [`insert`](insert.md),
|
||||
[`update`](update.md), and [`operator[]`](operator%5B%5D.md) for a non-existing key) can yield a reallocation, in
|
||||
which case all iterators (including the [`end()`](end.md) iterator) and all references to the elements are invalidated.
|
||||
|
||||
## Requirements
|
||||
|
||||
|
||||
@@ -24,6 +24,17 @@ void insert(const_iterator first, const_iterator last);
|
||||
4. Inserts elements from initializer list `ilist` into array before iterator `pos`.
|
||||
5. Inserts elements from range `[first, last)` into object.
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators
|
||||
(including the [`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the
|
||||
[`end()`](end.md) iterator is invalidated. Also, any iterator or reference after the insertion point will point to the
|
||||
same index which is now a different value.
|
||||
|
||||
For [`ordered_json`](../ordered_json.md), also adding an element to an **object** can yield a reallocation which again
|
||||
invalidates all iterators and all references. Also, any iterator or reference after the insertion point will point to
|
||||
the same index which is now a different value.
|
||||
|
||||
## Parameters
|
||||
|
||||
`pos` (in)
|
||||
|
||||
@@ -8,26 +8,36 @@ This exception is thrown if iterators passed to a library function do not match
|
||||
|
||||
Exceptions have ids 2xx (see [list of iterator errors](../../home/exceptions.md#iterator-errors)).
|
||||
|
||||
```plantuml
|
||||
std::exception <|-- basic_json::exception
|
||||
basic_json::exception <|-- basic_json::parse_error
|
||||
basic_json::exception <|-- basic_json::invalid_iterator
|
||||
basic_json::exception <|-- basic_json::type_error
|
||||
basic_json::exception <|-- basic_json::out_of_range
|
||||
basic_json::exception <|-- basic_json::other_error
|
||||
```mermaid
|
||||
classDiagram
|
||||
direction LR
|
||||
|
||||
class std_exception ["std::exception"] {
|
||||
<<interface>>
|
||||
}
|
||||
|
||||
interface std::exception {}
|
||||
class json_exception ["basic_json::exception"] {
|
||||
+const int id
|
||||
+const char* what() const
|
||||
}
|
||||
|
||||
class json_parse_error ["basic_json::parse_error"] {
|
||||
+const std::size_t byte
|
||||
}
|
||||
|
||||
class basic_json::exception {
|
||||
+ const int id
|
||||
+ const char* what() const
|
||||
}
|
||||
class json_invalid_iterator ["basic_json::invalid_iterator"]
|
||||
class json_type_error ["basic_json::type_error"]
|
||||
class json_out_of_range ["basic_json::out_of_range"]
|
||||
class json_other_error ["basic_json::other_error"]
|
||||
|
||||
class basic_json::parse_error {
|
||||
+ const std::size_t byte
|
||||
}
|
||||
std_exception <|-- json_exception
|
||||
json_exception <|-- json_parse_error
|
||||
json_exception <|-- json_invalid_iterator
|
||||
json_exception <|-- json_type_error
|
||||
json_exception <|-- json_out_of_range
|
||||
json_exception <|-- json_other_error
|
||||
|
||||
class basic_json::invalid_iterator #FFFF00 {}
|
||||
style json_invalid_iterator fill:#CCCCFF
|
||||
```
|
||||
|
||||
## Member functions
|
||||
|
||||
@@ -66,7 +66,7 @@ When iterating over an array, `key()` will return the index of the element as st
|
||||
!!! danger "Lifetime issues"
|
||||
|
||||
Using `items()` on temporary objects is dangerous. Make sure the object's lifetime exceeds the iteration. See
|
||||
<https://github.com/nlohmann/json/issues/2040> for more information.
|
||||
[#2040](https://github.com/nlohmann/json/issues/2040) for more information.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@@ -27,6 +27,15 @@ reference operator+=(initializer_list_t init);
|
||||
`init` is converted into an object element and added using `operator+=(const typename object_t::value_type&)`.
|
||||
Otherwise, `init` is converted to a JSON value and added using `operator+=(basic_json&&)`.
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators (including
|
||||
the [`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the
|
||||
[`end()`](end.md) iterator is invalidated.
|
||||
|
||||
For [`ordered_json`](../ordered_json.md), also adding an element to an **object** can yield a reallocation which again
|
||||
invalidates all iterators and all references.
|
||||
|
||||
## Parameters
|
||||
|
||||
`val` (in)
|
||||
@@ -103,6 +112,11 @@ interpreted as `object_t::value_type` or `std::initializer_list<basic_json>`, se
|
||||
--8<-- "examples/push_back__initializer_list.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [emplace_back](emplace_back.md) add a value to an array
|
||||
- [push_back](push_back.md) add a value to an array/object
|
||||
|
||||
## Version history
|
||||
|
||||
1. Since version 1.0.0.
|
||||
|
||||
@@ -34,6 +34,15 @@ const_reference operator[](const json_pointer& ptr) const;
|
||||
[`string_t`](string_t.md) using [`object_comparator_t`](object_comparator_t.md).
|
||||
This can also be a string view (C++17).
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
For the non-const versions 1. and 4., when passing an **array** index that does not exist, it is created and filled with
|
||||
a `#!json null` value before a reference to it is returned. For this, a reallocation can happen, in which case all
|
||||
iterators (including the [`end()`](end.md) iterator) and all references to the elements are invalidated.
|
||||
|
||||
For [`ordered_json`](../ordered_json.md), also passing an **object key** to the non-const versions 2., 3., and 4., a
|
||||
reallocation can happen which again invalidates all iterators and all references.
|
||||
|
||||
## Parameters
|
||||
|
||||
`idx` (in)
|
||||
|
||||
@@ -8,26 +8,36 @@ This exception is thrown in case of errors that cannot be classified with the ot
|
||||
|
||||
Exceptions have ids 5xx (see [list of other errors](../../home/exceptions.md#further-exceptions)).
|
||||
|
||||
```plantuml
|
||||
std::exception <|-- basic_json::exception
|
||||
basic_json::exception <|-- basic_json::parse_error
|
||||
basic_json::exception <|-- basic_json::invalid_iterator
|
||||
basic_json::exception <|-- basic_json::type_error
|
||||
basic_json::exception <|-- basic_json::out_of_range
|
||||
basic_json::exception <|-- basic_json::other_error
|
||||
```mermaid
|
||||
classDiagram
|
||||
direction LR
|
||||
|
||||
class std_exception ["std::exception"] {
|
||||
<<interface>>
|
||||
}
|
||||
|
||||
interface std::exception {}
|
||||
class json_exception ["basic_json::exception"] {
|
||||
+const int id
|
||||
+const char* what() const
|
||||
}
|
||||
|
||||
class json_parse_error ["basic_json::parse_error"] {
|
||||
+const std::size_t byte
|
||||
}
|
||||
|
||||
class basic_json::exception {
|
||||
+ const int id
|
||||
+ const char* what() const
|
||||
}
|
||||
class json_invalid_iterator ["basic_json::invalid_iterator"]
|
||||
class json_type_error ["basic_json::type_error"]
|
||||
class json_out_of_range ["basic_json::out_of_range"]
|
||||
class json_other_error ["basic_json::other_error"]
|
||||
|
||||
class basic_json::parse_error {
|
||||
+ const std::size_t byte
|
||||
}
|
||||
std_exception <|-- json_exception
|
||||
json_exception <|-- json_parse_error
|
||||
json_exception <|-- json_invalid_iterator
|
||||
json_exception <|-- json_type_error
|
||||
json_exception <|-- json_out_of_range
|
||||
json_exception <|-- json_other_error
|
||||
|
||||
class basic_json::other_error #FFFF00 {}
|
||||
style json_other_error fill:#CCCCFF
|
||||
```
|
||||
|
||||
## Member functions
|
||||
|
||||
@@ -9,26 +9,36 @@ instance in case of array indices or nonexisting object keys.
|
||||
|
||||
Exceptions have ids 4xx (see [list of out-of-range errors](../../home/exceptions.md#out-of-range)).
|
||||
|
||||
```plantuml
|
||||
std::exception <|-- basic_json::exception
|
||||
basic_json::exception <|-- basic_json::parse_error
|
||||
basic_json::exception <|-- basic_json::invalid_iterator
|
||||
basic_json::exception <|-- basic_json::type_error
|
||||
basic_json::exception <|-- basic_json::out_of_range
|
||||
basic_json::exception <|-- basic_json::other_error
|
||||
```mermaid
|
||||
classDiagram
|
||||
direction LR
|
||||
|
||||
class std_exception ["std::exception"] {
|
||||
<<interface>>
|
||||
}
|
||||
|
||||
interface std::exception {}
|
||||
class json_exception ["basic_json::exception"] {
|
||||
+const int id
|
||||
+const char* what() const
|
||||
}
|
||||
|
||||
class json_parse_error ["basic_json::parse_error"] {
|
||||
+const std::size_t byte
|
||||
}
|
||||
|
||||
class basic_json::exception {
|
||||
+ const int id
|
||||
+ const char* what() const
|
||||
}
|
||||
class json_invalid_iterator ["basic_json::invalid_iterator"]
|
||||
class json_type_error ["basic_json::type_error"]
|
||||
class json_out_of_range ["basic_json::out_of_range"]
|
||||
class json_other_error ["basic_json::other_error"]
|
||||
|
||||
class basic_json::parse_error {
|
||||
+ const std::size_t byte
|
||||
}
|
||||
std_exception <|-- json_exception
|
||||
json_exception <|-- json_parse_error
|
||||
json_exception <|-- json_invalid_iterator
|
||||
json_exception <|-- json_type_error
|
||||
json_exception <|-- json_out_of_range
|
||||
json_exception <|-- json_other_error
|
||||
|
||||
class basic_json::out_of_range #FFFF00 {}
|
||||
style json_out_of_range fill:#CCCCFF
|
||||
```
|
||||
|
||||
## Member functions
|
||||
|
||||
@@ -28,9 +28,9 @@ static basic_json parse(IteratorType first, IteratorType last,
|
||||
: A compatible input, for instance:
|
||||
|
||||
- an `std::istream` object
|
||||
- a `FILE` pointer (must not be null)
|
||||
- a `FILE` pointer (throws if null)
|
||||
- a C-style array of characters
|
||||
- a pointer to a null-terminated string of single byte characters
|
||||
- a pointer to a null-terminated string of single byte characters (throws if null)
|
||||
- a `std::string`
|
||||
- an object `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators.
|
||||
|
||||
@@ -73,10 +73,11 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
||||
|
||||
## 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
|
||||
- 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.
|
||||
- Throws [`parse_error.103`](../../home/exceptions.md#jsonexceptionparse_error103) if `to_unicode` fails.
|
||||
|
||||
## Complexity
|
||||
|
||||
@@ -86,12 +87,7 @@ super-linear complexity.
|
||||
|
||||
## Notes
|
||||
|
||||
(1) A UTF-8 byte order mark is silently ignored.
|
||||
|
||||
!!! danger "Runtime assertion"
|
||||
|
||||
The precondition that a passed `#!cpp FILE` pointer must not be null is enforced with a
|
||||
[runtime assertion](../../features/assertions.md).
|
||||
A UTF-8 byte order mark is silently ignored.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -203,6 +199,7 @@ super-linear complexity.
|
||||
- Added in version 1.0.0.
|
||||
- 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.11.4.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
|
||||
@@ -11,24 +11,36 @@ Member `byte` holds the byte index of the last read character in the input file
|
||||
|
||||
Exceptions have ids 1xx (see [list of parse errors](../../home/exceptions.md#parse-errors)).
|
||||
|
||||
```plantuml
|
||||
std::exception <|-- basic_json::exception
|
||||
basic_json::exception <|-- basic_json::parse_error
|
||||
basic_json::exception <|-- basic_json::invalid_iterator
|
||||
basic_json::exception <|-- basic_json::type_error
|
||||
basic_json::exception <|-- basic_json::out_of_range
|
||||
basic_json::exception <|-- basic_json::other_error
|
||||
```mermaid
|
||||
classDiagram
|
||||
direction LR
|
||||
|
||||
class std_exception ["std::exception"] {
|
||||
<<interface>>
|
||||
}
|
||||
|
||||
interface std::exception {}
|
||||
class json_exception ["basic_json::exception"] {
|
||||
+const int id
|
||||
+const char* what() const
|
||||
}
|
||||
|
||||
class json_parse_error ["basic_json::parse_error"] {
|
||||
+const std::size_t byte
|
||||
}
|
||||
|
||||
class basic_json::exception {
|
||||
+ const int id
|
||||
+ const char* what() const
|
||||
}
|
||||
class json_invalid_iterator ["basic_json::invalid_iterator"]
|
||||
class json_type_error ["basic_json::type_error"]
|
||||
class json_out_of_range ["basic_json::out_of_range"]
|
||||
class json_other_error ["basic_json::other_error"]
|
||||
|
||||
class basic_json::parse_error #FFFF00 {
|
||||
+ const std::size_t byte
|
||||
}
|
||||
std_exception <|-- json_exception
|
||||
json_exception <|-- json_parse_error
|
||||
json_exception <|-- json_invalid_iterator
|
||||
json_exception <|-- json_type_error
|
||||
json_exception <|-- json_out_of_range
|
||||
json_exception <|-- json_other_error
|
||||
|
||||
style json_parse_error fill:#CCCCFF
|
||||
```
|
||||
|
||||
## Member functions
|
||||
|
||||
@@ -27,6 +27,15 @@ void push_back(initializer_list_t init);
|
||||
`init` is converted into an object element and added using `push_back(const typename object_t::value_type&)`.
|
||||
Otherwise, `init` is converted to a JSON value and added using `push_back(basic_json&&)`.
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators (including
|
||||
the [`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the
|
||||
[`end()`](end.md) iterator is invalidated.
|
||||
|
||||
For [`ordered_json`](../ordered_json.md), also adding an element to an **object** can yield a reallocation which again
|
||||
invalidates all iterators and all references.
|
||||
|
||||
## Parameters
|
||||
|
||||
`val` (in)
|
||||
@@ -99,6 +108,11 @@ All functions can throw the following exception:
|
||||
--8<-- "examples/push_back__initializer_list.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [emplace_back](emplace_back.md) add a value to an array
|
||||
- [operator+=](operator+=.md) add a value to an array/object
|
||||
|
||||
## Version history
|
||||
|
||||
1. Since version 1.0.0.
|
||||
|
||||
@@ -9,26 +9,36 @@ does not match the expected semantics.
|
||||
|
||||
Exceptions have ids 3xx (see [list of type errors](../../home/exceptions.md#type-errors)).
|
||||
|
||||
```plantuml
|
||||
std::exception <|-- basic_json::exception
|
||||
basic_json::exception <|-- basic_json::parse_error
|
||||
basic_json::exception <|-- basic_json::invalid_iterator
|
||||
basic_json::exception <|-- basic_json::type_error
|
||||
basic_json::exception <|-- basic_json::out_of_range
|
||||
basic_json::exception <|-- basic_json::other_error
|
||||
```mermaid
|
||||
classDiagram
|
||||
direction LR
|
||||
|
||||
class std_exception ["std::exception"] {
|
||||
<<interface>>
|
||||
}
|
||||
|
||||
interface std::exception {}
|
||||
class json_exception ["basic_json::exception"] {
|
||||
+const int id
|
||||
+const char* what() const
|
||||
}
|
||||
|
||||
class json_parse_error ["basic_json::parse_error"] {
|
||||
+const std::size_t byte
|
||||
}
|
||||
|
||||
class basic_json::exception {
|
||||
+ const int id
|
||||
+ const char* what() const
|
||||
}
|
||||
class json_invalid_iterator ["basic_json::invalid_iterator"]
|
||||
class json_type_error ["basic_json::type_error"]
|
||||
class json_out_of_range ["basic_json::out_of_range"]
|
||||
class json_other_error ["basic_json::other_error"]
|
||||
|
||||
class basic_json::parse_error {
|
||||
+ const std::size_t byte
|
||||
}
|
||||
std_exception <|-- json_exception
|
||||
json_exception <|-- json_parse_error
|
||||
json_exception <|-- json_invalid_iterator
|
||||
json_exception <|-- json_type_error
|
||||
json_exception <|-- json_out_of_range
|
||||
json_exception <|-- json_other_error
|
||||
|
||||
class basic_json::type_error #FFFF00 {}
|
||||
style json_type_error fill:#CCCCFF
|
||||
```
|
||||
|
||||
## Member functions
|
||||
|
||||
@@ -17,6 +17,11 @@ recursively merges objects with common keys.
|
||||
The function is motivated by Python's [dict.update](https://docs.python.org/3.6/library/stdtypes.html#dict.update)
|
||||
function.
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
For [`ordered_json`](../ordered_json.md), adding a value to an object can yield a reallocation, in which case all
|
||||
iterators (including the `end()` iterator) and all references to the elements are invalidated.
|
||||
|
||||
## Parameters
|
||||
|
||||
`j` (in)
|
||||
|
||||
@@ -42,7 +42,6 @@ header. See also the [macro overview page](../../features/macros.md).
|
||||
- [**JSON_DISABLE_ENUM_SERIALIZATION**](json_disable_enum_serialization.md) - switch off default serialization/deserialization functions for enums
|
||||
- [**JSON_USE_IMPLICIT_CONVERSIONS**](json_use_implicit_conversions.md) - control implicit conversions
|
||||
|
||||
<!-- comment-->
|
||||
## Comparison behavior
|
||||
|
||||
- [**JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON**](json_use_legacy_discarded_value_comparison.md) -
|
||||
@@ -50,6 +49,20 @@ header. See also the [macro overview page](../../features/macros.md).
|
||||
|
||||
## Serialization/deserialization macros
|
||||
|
||||
- Enum: [**NLOHMANN_JSON_SERIALIZE_ENUM**](nlohmann_json_serialize_enum.md)
|
||||
- Class/struct:
|
||||
- Do you need to serialize private variables?
|
||||
- Yes? Do you only need serialization?
|
||||
- Yes? `NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE`
|
||||
- No? Allow deserialization of JSON values with missing values?
|
||||
- Yes? `NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT`
|
||||
- No? `NLOHMANN_DEFINE_TYPE_INTRUSIVE`
|
||||
- No? Do you only need serialization?
|
||||
- Yes? `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE`
|
||||
- No? Allow deserialization of JSON values with missing values?
|
||||
- Yes? `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT`
|
||||
- No? `NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE`
|
||||
|
||||
- [**NLOHMANN_DEFINE_TYPE_INTRUSIVE(type, member...)**<br>**NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(type, member...)**
|
||||
<br>**NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(type, member...)**][DefInt]
|
||||
\- serialization/deserialization of types _with_ access to private variables
|
||||
|
||||
@@ -27,7 +27,7 @@ By default, implicit conversions are enabled.
|
||||
!!! hint "CMake option"
|
||||
|
||||
Implicit conversions can also be controlled with the CMake option
|
||||
[`JSON_ImplicitConversions`](../../integration/cmake.md#json_legacydiscardedvaluecomparison)
|
||||
[`JSON_ImplicitConversions`](../../integration/cmake.md#json_implicitconversions)
|
||||
(`ON` by default) which defines `JSON_USE_IMPLICIT_CONVERSIONS` accordingly.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT
|
||||
|
||||
# NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT
|
||||
<h1>NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT,
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT</h1>
|
||||
|
||||
```cpp
|
||||
#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(type, base_type, member...) // (1)
|
||||
@@ -19,7 +18,6 @@ Like [`NLOHMANN_DEFINE_TYPE_INTRUSIVE`](nlohmann_define_type_intrusive.md), they
|
||||
Like [`NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE`](nlohmann_define_type_non_intrusive.md),
|
||||
they **cannot** access private members.
|
||||
|
||||
|
||||
The first parameter is the name of the derived class/struct,
|
||||
the second parameter is the name of the base class/struct and all remaining parameters name the members.
|
||||
The base type **must** be already serializable/deserializable.
|
||||
|
||||
@@ -17,7 +17,7 @@ using namespace nlohmann;
|
||||
```
|
||||
|
||||
This is suggested to ease migration to the next major version release of the library. See
|
||||
['JSON_USE_GLOBAL_UDLS`](macros/json_use_global_udls.md#notes) for details.
|
||||
[`JSON_USE_GLOBAL_UDLS`](macros/json_use_global_udls.md#notes) for details.
|
||||
|
||||
## Parameters
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ using namespace nlohmann::literals::json_literals;
|
||||
using namespace nlohmann;
|
||||
```
|
||||
This is suggested to ease migration to the next major version release of the library. See
|
||||
['JSON_USE_GLOBAL_UDLS`](macros/json_use_global_udls.md#notes) for details.
|
||||
[`JSON_USE_GLOBAL_UDLS`](macros/json_use_global_udls.md#notes) for details.
|
||||
|
||||
## Parameters
|
||||
|
||||
|
||||
@@ -6,6 +6,13 @@ using ordered_json = basic_json<ordered_map>;
|
||||
|
||||
This type preserves the insertion order of object keys.
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
The type is based on [`ordered_map`](ordered_map.md) which in turn uses a `std::vector` to store object elements.
|
||||
Therefore, adding object elements can yield a reallocation in which case all iterators (including the
|
||||
[`end()`](basic_json/end.md) iterator) and all references to the elements are invalidated. Also, any iterator or
|
||||
reference after the insertion point will point to the same index which is now a different value.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
@@ -23,6 +23,11 @@ A minimal map-like container that preserves insertion order for use within [`nlo
|
||||
`Allocator`
|
||||
: allocator type
|
||||
|
||||
## Iterator invalidation
|
||||
|
||||
The type uses a `std::vector` to store object elements. Therefore, adding elements can yield a reallocation in which
|
||||
case all iterators (including the `end()` iterator) and all references to the elements are invalidated.
|
||||
|
||||
## Member types
|
||||
|
||||
- **key_type** - key type (`Key`)
|
||||
|
||||
Reference in New Issue
Block a user