This commit is contained in:
nlohmann
2026-10-27 12:14:00 +00:00
parent b36f8a9821
commit 11a863958e
1180 changed files with 14211 additions and 6025 deletions
+7 -7
View File
@@ -15,7 +15,7 @@ basic_json_view at(IntegerType idx) const;
basic_json_view at(const json_pointer& ptr) const;
```
1. Returns the value of the object member with key `key` -- the first one, should the key occur more than once (see
1. Returns the value of the object member with key `key` — the first one, should the key occur more than once (see
[Notes on duplicate keys](operator[].md#notes)).
2. Returns the array element at index `idx`. The template accepts every integer type except `#!cpp bool` and
`#!cpp std::size_t` and forwards to the `size_type` overload, as for [`operator[]`](operator[].md); a negative
@@ -62,7 +62,7 @@ Strong guarantee: there are no changes to the view or the document it refers to.
- Throws [`out_of_range.401`](../../home/exceptions.md#jsonexceptionout_of_range401) if an array index in `ptr`
is out of range.
- Throws [`out_of_range.402`](../../home/exceptions.md#jsonexceptionout_of_range402) if a reference token is
`#!cpp "-"` at an array -- `at` never inserts an element, so `#!cpp "-"` is always invalid.
`#!cpp "-"` at an array — `at` never inserts an element, so `#!cpp "-"` is always invalid.
- Throws [`out_of_range.403`](../../home/exceptions.md#jsonexceptionout_of_range403) if a reference token names
an object member that does not exist.
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if `ptr` cannot be resolved
@@ -76,7 +76,7 @@ None of these exceptions carry a [`JSON_DIAGNOSTICS`](../macros/json_diagnostics
1. Linear in the number of members: as for [`ordered_json`](../ordered_json.md), members are compared one after
another, in document order, stopping at the first match. Each comparison first checks the
key's length -- already known from the index, without reading the key bytes -- before comparing its content.
key's length — already known from the index, without reading the key bytes — before comparing its content.
Objects with 128 or more members get a hash index of their keys while parsing, so that a lookup in them takes
constant time on average.
2. Linear in `idx`: elements are skipped one at a time from the first one, since they are not a fixed size in the
@@ -95,7 +95,7 @@ None of these exceptions carry a [`JSON_DIAGNOSTICS`](../macros/json_diagnostics
the last value.
Unlike [`operator[]`](operator[].md), which returns a [discarded](is_discarded.md) view for a missing key or an
out-of-range index, `at` always throws -- exactly as `BasicJsonType::at` does, and with the same messages, so
out-of-range index, `at` always throws — exactly as `BasicJsonType::at` does, and with the same messages, so
existing error handling written against `BasicJsonType::at` keeps working unchanged when switched to a view. This
also holds for overload 3: unlike [`operator[]`](operator[].md) with a JSON pointer, which returns a discarded view
for a missing key or an out-of-range index, `at` throws for those too (`out_of_range.403`/`out_of_range.401`).
@@ -105,7 +105,7 @@ for a missing key or an out-of-range index, `at` throws for those too (`out_of_r
??? example "Example: (1)/(2) access specified element with bounds checking"
The example below reads required fields out of a service configuration with `at`, and shows that the exceptions
it throws -- for a wrong type and for a missing key -- carry the same messages
it throws — for a wrong type and for a missing key — carry the same messages
[`BasicJsonType::at`](../basic_json/at.md) would produce for the same JSON text.
```cpp
@@ -211,8 +211,8 @@ for a missing key or an out-of-range index, `at` throws for those too (`out_of_r
## See also
- [operator[]](operator[].md) - access specified element (returns a discarded view instead of throwing)
- [front](front.md), [back](back.md) - access the first or last element
- [`operator[]`](operator[].md) - access specified element (returns a discarded view instead of throwing)
- [`front`](front.md), [`back`](back.md) - access the first or last element
- [`BasicJsonType::at`](../basic_json/at.md) - the corresponding function of `basic_json`
- [`json_pointer`](../json_pointer/index.md) - JSON pointer type used by overload 3
File diff suppressed because one or more lines are too long
+7 -7
View File
@@ -15,7 +15,7 @@ basic_json_view at(IntegerType idx) const;
basic_json_view at(const json_pointer& ptr) const;
```
1. Returns the value of the object member with key `key` -- the first one, should the key occur more than once (see [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes)).
1. Returns the value of the object member with key `key` — the first one, should the key occur more than once (see [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes)).
1. Returns the array element at index `idx`. The template accepts every integer type except `bool` and `std::size_t` and forwards to the `size_type` overload, as for [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md); a negative `idx` is out of range.
1. Returns the value a JSON pointer `ptr` refers to, starting at this value.
@@ -49,7 +49,7 @@ Strong guarantee: there are no changes to the view or the document it refers to.
- Throws [`parse_error.106`](https://json.nlohmann.me/home/exceptions/#jsonexceptionparse_error106) if an array index in `ptr` begins with `'0'`.
- Throws [`parse_error.109`](https://json.nlohmann.me/home/exceptions/#jsonexceptionparse_error109) if an array index in `ptr` is not a number.
- Throws [`out_of_range.401`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range401) if an array index in `ptr` is out of range.
- Throws [`out_of_range.402`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range402) if a reference token is `"-"` at an array -- `at` never inserts an element, so `"-"` is always invalid.
- Throws [`out_of_range.402`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range402) if a reference token is `"-"` at an array — `at` never inserts an element, so `"-"` is always invalid.
- Throws [`out_of_range.403`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range403) if a reference token names an object member that does not exist.
- Throws [`out_of_range.404`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range404) if `ptr` cannot be resolved because a reference token is used on a primitive value.
@@ -57,7 +57,7 @@ None of these exceptions carry a [`JSON_DIAGNOSTICS`](https://json.nlohmann.me/a
## Complexity
1. Linear in the number of members: as for [`ordered_json`](https://json.nlohmann.me/api/ordered_json/index.md), members are compared one after another, in document order, stopping at the first match. Each comparison first checks the key's length -- already known from the index, without reading the key bytes -- before comparing its content. Objects with 128 or more members get a hash index of their keys while parsing, so that a lookup in them takes constant time on average.
1. Linear in the number of members: as for [`ordered_json`](https://json.nlohmann.me/api/ordered_json/index.md), members are compared one after another, in document order, stopping at the first match. Each comparison first checks the key's length — already known from the index, without reading the key bytes — before comparing its content. Objects with 128 or more members get a hash index of their keys while parsing, so that a lookup in them takes constant time on average.
1. Linear in `idx`: elements are skipped one at a time from the first one, since they are not a fixed size in the index (unlike `BasicJsonType`'s array, which is random-access). Constant if no element of the array is an array or object, since the elements are then adjacent in the index.
1. Linear in the number of reference tokens of `ptr` and, for each token, in the number of members of the object at that level (as 1.) or the index into the array (as 2.).
@@ -67,13 +67,13 @@ Duplicate keys: the first member wins
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) and `parse()` keep. See the [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes) of `operator[]` and [Duplicate keys](https://json.nlohmann.me/features/json_view/#duplicate-keys) for the reasons and for how to get the last value.
Unlike [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md), which returns a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view for a missing key or an out-of-range index, `at` always throws -- exactly as `BasicJsonType::at` does, and with the same messages, so existing error handling written against `BasicJsonType::at` keeps working unchanged when switched to a view. This also holds for overload 3: unlike [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) with a JSON pointer, which returns a discarded view for a missing key or an out-of-range index, `at` throws for those too (`out_of_range.403`/`out_of_range.401`).
Unlike [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md), which returns a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view for a missing key or an out-of-range index, `at` always throws — exactly as `BasicJsonType::at` does, and with the same messages, so existing error handling written against `BasicJsonType::at` keeps working unchanged when switched to a view. This also holds for overload 3: unlike [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) with a JSON pointer, which returns a discarded view for a missing key or an out-of-range index, `at` throws for those too (`out_of_range.403`/`out_of_range.401`).
## Examples
Example: (1)/(2) access specified element with bounds checking
The example below reads required fields out of a service configuration with `at`, and shows that the exceptions it throws -- for a wrong type and for a missing key -- carry the same messages [`BasicJsonType::at`](https://json.nlohmann.me/api/basic_json/at/index.md) would produce for the same JSON text.
The example below reads required fields out of a service configuration with `at`, and shows that the exceptions it throws — for a wrong type and for a missing key — carry the same messages [`BasicJsonType::at`](https://json.nlohmann.me/api/basic_json/at/index.md) would produce for the same JSON text.
```
#include <iostream>
@@ -173,8 +173,8 @@ Output:
## See also
- [operator[]](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) - access specified element (returns a discarded view instead of throwing)
- [front](https://json.nlohmann.me/api/basic_json_view/front/index.md), [back](https://json.nlohmann.me/api/basic_json_view/back/index.md) - access the first or last element
- [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) - access specified element (returns a discarded view instead of throwing)
- [`front`](https://json.nlohmann.me/api/basic_json_view/front/index.md), [`back`](https://json.nlohmann.me/api/basic_json_view/back/index.md) - access the first or last element
- [`BasicJsonType::at`](https://json.nlohmann.me/api/basic_json/at/index.md) - the corresponding function of `basic_json`
- [`json_pointer`](https://json.nlohmann.me/api/json_pointer/index.md) - JSON pointer type used by overload 3
+1 -1
View File
@@ -83,7 +83,7 @@ Unlike [`BasicJsonType::back()`](../basic_json/back.md), which has undefined beh
## See also
- [front](front.md) - access the first element
- [`front`](front.md) - access the first element
- [`BasicJsonType::back`](../basic_json/back.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -71,7 +71,7 @@ Output:
## See also
- [front](https://json.nlohmann.me/api/basic_json_view/front/index.md) - access the first element
- [`front`](https://json.nlohmann.me/api/basic_json_view/front/index.md) - access the first element
- [`BasicJsonType::back`](https://json.nlohmann.me/api/basic_json/back/index.md) - the corresponding function of `basic_json`
## Version history
+4 -3
View File
@@ -74,9 +74,10 @@ placeholder for "no value yet" and later be assigned a real view.
## See also
- [is_discarded](is_discarded.md) - return whether the view is invalid
- [root](../basic_json_document/root.md) - the view of a document's root value
- [view_mode](../view_mode.md) - whether a document and its views can be edited
- [`is_discarded`](is_discarded.md) - return whether the view is invalid
- [`root`](../basic_json_document/root.md) - the view of a document's root value
- [`view_mode`](../view_mode.md) - whether a document and its views can be edited
- [Zero-copy JSON views](../../features/json_view.md#ownership-and-lifetime) - how long a view stays valid
## Version history
File diff suppressed because one or more lines are too long
+4 -3
View File
@@ -64,9 +64,10 @@ true
## See also
- [is_discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) - return whether the view is invalid
- [root](https://json.nlohmann.me/api/basic_json_document/root/index.md) - the view of a document's root value
- [view_mode](https://json.nlohmann.me/api/view_mode/index.md) - whether a document and its views can be edited
- [`is_discarded`](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) - return whether the view is invalid
- [`root`](https://json.nlohmann.me/api/basic_json_document/root/index.md) - the view of a document's root value
- [`view_mode`](https://json.nlohmann.me/api/view_mode/index.md) - whether a document and its views can be edited
- [Zero-copy JSON views](https://json.nlohmann.me/features/json_view/#ownership-and-lifetime) - how long a view stays valid
## Version history
+5 -5
View File
@@ -5,7 +5,7 @@ iterator begin() const noexcept;
```
Returns an iterator to the first element of an array, or the first member value of an object, in **document order**
-- the order the values appear in the source text, not sorted by key. A primitive value iterates as a range of one
— the order the values appear in the source text, not sorted by key. A primitive value iterates as a range of one
element (itself), and a `#!json null` value or a [discarded](is_discarded.md) view iterates as an empty range.
## Return value
@@ -22,7 +22,7 @@ Constant.
## Notes
For an object, iteration visits **every** member, including all occurrences of a duplicate key -- unlike
For an object, iteration visits **every** member, including all occurrences of a duplicate key — unlike
[`operator[]`](operator[].md), [`at`](at.md), [`find`](find.md), and [`contains`](contains.md),
which all resolve to the *first* member with a given key. See the
[Notes on duplicate keys](operator[].md#notes) of `operator[]`.
@@ -76,9 +76,9 @@ the duplicates.
## See also
- [end](end.md) - returns an iterator to one past the last element
- [cbegin](cbegin.md) - returns a const iterator to the first element
- [items](items.md) - access iterator member functions in range-based for
- [`end`](end.md) - returns an iterator to one past the last element
- [`cbegin`](cbegin.md) - returns a const iterator to the first element
- [`items`](items.md) - access iterator member functions in range-based for
- [`BasicJsonType::begin`](../basic_json/begin.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+5 -5
View File
@@ -4,7 +4,7 @@
iterator begin() const noexcept;
```
Returns an iterator to the first element of an array, or the first member value of an object, in **document order** -- the order the values appear in the source text, not sorted by key. A primitive value iterates as a range of one element (itself), and a `null` value or a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view iterates as an empty range.
Returns an iterator to the first element of an array, or the first member value of an object, in **document order** — the order the values appear in the source text, not sorted by key. A primitive value iterates as a range of one element (itself), and a `null` value or a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view iterates as an empty range.
## Return value
@@ -20,7 +20,7 @@ Constant.
## Notes
For an object, iteration visits **every** member, including all occurrences of a duplicate key -- unlike [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md), [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md), and [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md), which all resolve to the *first* member with a given key. See the [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes) of `operator[]`.
For an object, iteration visits **every** member, including all occurrences of a duplicate key — unlike [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md), [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md), and [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md), which all resolve to the *first* member with a given key. See the [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes) of `operator[]`.
Because objects are iterated in document order rather than sorted by key, the order seen here can differ from what iterating the [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md)d `BasicJsonType` value would produce: a `basic_json` object (`std::map`-backed by default) sorts its keys, while a view does not.
@@ -63,9 +63,9 @@ message="started"
## See also
- [end](https://json.nlohmann.me/api/basic_json_view/end/index.md) - returns an iterator to one past the last element
- [cbegin](https://json.nlohmann.me/api/basic_json_view/cbegin/index.md) - returns a const iterator to the first element
- [items](https://json.nlohmann.me/api/basic_json_view/items/index.md) - access iterator member functions in range-based for
- [`end`](https://json.nlohmann.me/api/basic_json_view/end/index.md) - returns an iterator to one past the last element
- [`cbegin`](https://json.nlohmann.me/api/basic_json_view/cbegin/index.md) - returns a const iterator to the first element
- [`items`](https://json.nlohmann.me/api/basic_json_view/items/index.md) - access iterator member functions in range-based for
- [`BasicJsonType::begin`](https://json.nlohmann.me/api/basic_json/begin/index.md) - the corresponding function of `basic_json`
## Version history
+3 -3
View File
@@ -25,7 +25,7 @@ Constant.
??? example
The example below sums many measurements with `std::accumulate`, using `cbegin()`/[`cend()`](cend.md) as the
range -- the same way it would for any standard container -- without ever materializing the whole array into a
range — the same way it would for any standard container — without ever materializing the whole array into a
`BasicJsonType` value.
```cpp
@@ -65,8 +65,8 @@ Constant.
## See also
- [begin](begin.md) - returns an iterator to the first element
- [cend](cend.md) - returns a const iterator to one past the last element
- [`begin`](begin.md) - returns an iterator to the first element
- [`cend`](cend.md) - returns a const iterator to one past the last element
- [`BasicJsonType::cbegin`](../basic_json/cbegin.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -22,7 +22,7 @@ Constant.
Example
The example below sums many measurements with `std::accumulate`, using `cbegin()`/[`cend()`](https://json.nlohmann.me/api/basic_json_view/cend/index.md) as the range -- the same way it would for any standard container -- without ever materializing the whole array into a `BasicJsonType` value.
The example below sums many measurements with `std::accumulate`, using `cbegin()`/[`cend()`](https://json.nlohmann.me/api/basic_json_view/cend/index.md) as the range — the same way it would for any standard container — without ever materializing the whole array into a `BasicJsonType` value.
```
#include <iostream>
@@ -59,8 +59,8 @@ Output:
## See also
- [begin](https://json.nlohmann.me/api/basic_json_view/begin/index.md) - returns an iterator to the first element
- [cend](https://json.nlohmann.me/api/basic_json_view/cend/index.md) - returns a const iterator to one past the last element
- [`begin`](https://json.nlohmann.me/api/basic_json_view/begin/index.md) - returns an iterator to the first element
- [`cend`](https://json.nlohmann.me/api/basic_json_view/cend/index.md) - returns a const iterator to one past the last element
- [`BasicJsonType::cbegin`](https://json.nlohmann.me/api/basic_json/cbegin/index.md) - the corresponding function of `basic_json`
## Version history
+3 -3
View File
@@ -25,7 +25,7 @@ Constant.
??? example
The example below checks that every record of a batch is an object with `std::all_of`, using
[`cbegin()`](cbegin.md)/`cend()` as the range -- the same way it would for any standard container -- before
[`cbegin()`](cbegin.md)/`cend()` as the range — the same way it would for any standard container — before
materializing any record of the batch.
```cpp
@@ -65,8 +65,8 @@ Constant.
## See also
- [end](end.md) - returns an iterator to one past the last element
- [cbegin](cbegin.md) - returns a const iterator to the first element
- [`end`](end.md) - returns an iterator to one past the last element
- [`cbegin`](cbegin.md) - returns a const iterator to the first element
- [`BasicJsonType::cend`](../basic_json/cend.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -22,7 +22,7 @@ Constant.
Example
The example below checks that every record of a batch is an object with `std::all_of`, using [`cbegin()`](https://json.nlohmann.me/api/basic_json_view/cbegin/index.md)/`cend()` as the range -- the same way it would for any standard container -- before materializing any record of the batch.
The example below checks that every record of a batch is an object with `std::all_of`, using [`cbegin()`](https://json.nlohmann.me/api/basic_json_view/cbegin/index.md)/`cend()` as the range — the same way it would for any standard container — before materializing any record of the batch.
```
#include <algorithm>
@@ -59,8 +59,8 @@ true
## See also
- [end](https://json.nlohmann.me/api/basic_json_view/end/index.md) - returns an iterator to one past the last element
- [cbegin](https://json.nlohmann.me/api/basic_json_view/cbegin/index.md) - returns a const iterator to the first element
- [`end`](https://json.nlohmann.me/api/basic_json_view/end/index.md) - returns an iterator to one past the last element
- [`cbegin`](https://json.nlohmann.me/api/basic_json_view/cbegin/index.md) - returns a const iterator to the first element
- [`BasicJsonType::cend`](https://json.nlohmann.me/api/basic_json/cend/index.md) - the corresponding function of `basic_json`
## Version history
+6 -6
View File
@@ -34,11 +34,11 @@ No-throw guarantee: this function never throws exceptions.
1. Linear in the number of members: as for [`ordered_json`](../ordered_json.md), members are compared one after
another, in document order, stopping at the first match. Each comparison first checks the
key's length -- already known from the index, without reading the key bytes -- before comparing its content.
key's length — already known from the index, without reading the key bytes — before comparing its content.
Objects with 128 or more members get a hash index of their keys while parsing, so that a lookup in them takes
constant time on average.
2. Linear in the number of reference tokens of `ptr` and, for each token, in the number of members of the object at
that level or the index into the array -- as for [`operator[]`](operator[].md#complexity) and
that level or the index into the array — as for [`operator[]`](operator[].md#complexity) and
[`at`](at.md#complexity) with a JSON pointer.
## Notes
@@ -50,7 +50,7 @@ No-throw guarantee: this function never throws exceptions.
`operator[]` and [Duplicate keys](../../features/json_view.md#duplicate-keys) for the reasons and for how to get
the last value.
Overload 1 always returns `#!cpp false` when the value is not an object -- including a [discarded](is_discarded.md)
Overload 1 always returns `#!cpp false` when the value is not an object — including a [discarded](is_discarded.md)
view.
!!! info "Postconditions"
@@ -175,9 +175,9 @@ view.
## See also
- [find](find.md) - find a value in an object
- [count](count.md) - returns the number of occurrences of a key
- [at](at.md), [operator[]](operator[].md) - resolve a JSON pointer and throw, or return a discarded view
- [`find`](find.md) - find a value in an object
- [`count`](count.md) - returns the number of occurrences of a key
- [`at`](at.md), [`operator[]`](operator[].md) - resolve a JSON pointer and throw, or return a discarded view
- [`BasicJsonType::contains`](../basic_json/contains.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+6 -6
View File
@@ -30,8 +30,8 @@ No-throw guarantee: this function never throws exceptions.
## Complexity
1. Linear in the number of members: as for [`ordered_json`](https://json.nlohmann.me/api/ordered_json/index.md), members are compared one after another, in document order, stopping at the first match. Each comparison first checks the key's length -- already known from the index, without reading the key bytes -- before comparing its content. Objects with 128 or more members get a hash index of their keys while parsing, so that a lookup in them takes constant time on average.
1. Linear in the number of reference tokens of `ptr` and, for each token, in the number of members of the object at that level or the index into the array -- as for [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#complexity) and [`at`](https://json.nlohmann.me/api/basic_json_view/at/#complexity) with a JSON pointer.
1. Linear in the number of members: as for [`ordered_json`](https://json.nlohmann.me/api/ordered_json/index.md), members are compared one after another, in document order, stopping at the first match. Each comparison first checks the key's length — already known from the index, without reading the key bytes — before comparing its content. Objects with 128 or more members get a hash index of their keys while parsing, so that a lookup in them takes constant time on average.
1. Linear in the number of reference tokens of `ptr` and, for each token, in the number of members of the object at that level or the index into the array — as for [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#complexity) and [`at`](https://json.nlohmann.me/api/basic_json_view/at/#complexity) with a JSON pointer.
## Notes
@@ -39,7 +39,7 @@ Duplicate keys: the first member wins
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) and `parse()` keep. See the [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes) of `operator[]` and [Duplicate keys](https://json.nlohmann.me/features/json_view/#duplicate-keys) for the reasons and for how to get the last value.
Overload 1 always returns `false` when the value is not an object -- including a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view.
Overload 1 always returns `false` when the value is not an object — including a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view.
Postconditions
@@ -151,9 +151,9 @@ false
## See also
- [find](https://json.nlohmann.me/api/basic_json_view/find/index.md) - find a value in an object
- [count](https://json.nlohmann.me/api/basic_json_view/count/index.md) - returns the number of occurrences of a key
- [at](https://json.nlohmann.me/api/basic_json_view/at/index.md), [operator[]](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) - resolve a JSON pointer and throw, or return a discarded view
- [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md) - find a value in an object
- [`count`](https://json.nlohmann.me/api/basic_json_view/count/index.md) - returns the number of occurrences of a key
- [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) - resolve a JSON pointer and throw, or return a discarded view
- [`BasicJsonType::contains`](https://json.nlohmann.me/api/basic_json/contains/index.md) - the corresponding function of `basic_json`
## Version history
+4 -4
View File
@@ -27,13 +27,13 @@ No-throw guarantee: this function never throws exceptions.
Linear in the number of members: unlike the lookup functions, `count()` does not stop at the first match, because it
has to count every member with the key. Members are compared one after another, in document order. Each comparison
first checks the key's length -- already known from the index, without reading the key bytes -- before comparing its
first checks the key's length — already known from the index, without reading the key bytes — before comparing its
content. The hash index of the keys of objects with 128 or more members does not help here, since every member
is visited.
## Notes
This method always returns `#!cpp 0` when the value is not an object -- including a [discarded](is_discarded.md)
This method always returns `#!cpp 0` when the value is not an object — including a [discarded](is_discarded.md)
view.
If the source text repeats a key, `count()` returns more than `#!cpp 1` for it, even though the
@@ -96,8 +96,8 @@ If the source text repeats a key, `count()` returns more than `#!cpp 1` for it,
## See also
- [find](find.md) - find a value in an object
- [contains](contains.md) - checks whether a key exists
- [`find`](find.md) - find a value in an object
- [`contains`](contains.md) - checks whether a key exists
- [`BasicJsonType::count`](../basic_json/count.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -22,11 +22,11 @@ No-throw guarantee: this function never throws exceptions.
## Complexity
Linear in the number of members: unlike the lookup functions, `count()` does not stop at the first match, because it has to count every member with the key. Members are compared one after another, in document order. Each comparison first checks the key's length -- already known from the index, without reading the key bytes -- before comparing its content. The hash index of the keys of objects with 128 or more members does not help here, since every member is visited.
Linear in the number of members: unlike the lookup functions, `count()` does not stop at the first match, because it has to count every member with the key. Members are compared one after another, in document order. Each comparison first checks the key's length — already known from the index, without reading the key bytes — before comparing its content. The hash index of the keys of objects with 128 or more members does not help here, since every member is visited.
## Notes
This method always returns `0` when the value is not an object -- including a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view.
This method always returns `0` when the value is not an object — including a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view.
If the source text repeats a key, `count()` returns more than `1` for it, even though the [materialized](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) value (like the result of `parse()`) would have only one member with that key. Hence `count(key) > 1` detects duplicate keys. This is unlike the lookup functions ([`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md), [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md), [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md)), which resolve to the *first* member; see the [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes) of `operator[]`.
@@ -80,8 +80,8 @@ transaction 2 has 2 "amount" fields
## See also
- [find](https://json.nlohmann.me/api/basic_json_view/find/index.md) - find a value in an object
- [contains](https://json.nlohmann.me/api/basic_json_view/contains/index.md) - checks whether a key exists
- [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md) - find a value in an object
- [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md) - checks whether a key exists
- [`BasicJsonType::count`](https://json.nlohmann.me/api/basic_json/count/index.md) - the corresponding function of `basic_json`
## Version history
+8 -7
View File
@@ -11,7 +11,7 @@ Serializes this value (and its subtree) directly from the flat index, without ev
first. With the default `#!cpp numbers == number_format::shortest`, the result is the same string
[`BasicJsonType::dump`](../basic_json/dump.md) would produce for the value
[`BasicJsonType::parse()`](../basic_json/parse.md) builds from the same source text, called with the same `indent`,
`indent_char`, and `ensure_ascii` -- except that members of an object appear in document order rather than sorted by
`indent_char`, and `ensure_ascii` — except that members of an object appear in document order rather than sorted by
key, and *every* occurrence of a repeated key is written rather than only the last one (see
[Notes on duplicate keys](operator[].md#notes)). For a `json_view` (whose `BasicJsonType` is not ordered), this means
`dump()` can print an object's members in a different order than [`materialize()`](materialize.md)`.dump()` of the
@@ -58,19 +58,19 @@ Linear in the size of the output text.
## Notes
The walk over the subtree is iterative, so the nesting depth it can write is limited by available memory only, not by
the call stack -- as for [`materialize()`](materialize.md).
the call stack — as for [`materialize()`](materialize.md).
Strings are escaped by the same rules as [`BasicJsonType::dump`](../basic_json/dump.md).
With `#!cpp numbers == number_format::shortest`, floats are written with the library's shortest round-trip conversion,
exactly as [`BasicJsonType::dump`](../basic_json/dump.md) would (e.g. `#!cpp 1.5`, `#!cpp 100.0`, `#!cpp 1e+100`), and
integers are copied from the source text -- already canonical in JSON, so this matches their shortest form too --
integers are copied from the source text — already canonical in JSON, so this matches their shortest form too —
except that `#!cpp -0` is written as `#!cpp 0`, the way [`BasicJsonType::parse()`](../basic_json/parse.md) reads it.
`#!cpp number_format::source` copies every number exactly as written in the source text instead, with no exception
for `#!cpp -0` -- `#!cpp 1.50`, `#!cpp 1E2`, `#!cpp -0.0`, `#!cpp -0`, or all digits of an integer literal with more
for `#!cpp -0` — `#!cpp 1.50`, `#!cpp 1E2`, `#!cpp -0.0`, `#!cpp -0`, or all digits of an integer literal with more
digits than any number type holds (such a literal is itself classified as a float, see
[What is different](../../features/json_view.md#what-is-different)) -- something `BasicJsonType` cannot do, since
[What is different](../../features/json_view.md#what-is-different)) — something `BasicJsonType` cannot do, since
parsing already reduces every number to its parsed value.
## Examples
@@ -134,9 +134,10 @@ parsing already reduces every number to its parsed value.
## See also
- [`number_format`](number_format.md) - how `dump()` writes numbers
- [operator<<](operator_ltlt.md) - serialize this value to a stream
- [materialize](materialize.md) - build a `BasicJsonType` value, e.g. to use `BasicJsonType::dump`'s `error_handler`
- [`operator<<`](operator_ltlt.md) - serialize this value to a stream
- [`materialize`](materialize.md) - build a `BasicJsonType` value, e.g. to use `BasicJsonType::dump`'s `error_handler`
- [`BasicJsonType::dump`](../basic_json/dump.md) - the corresponding function of `basic_json`
- [Zero-copy JSON views](../../features/json_view.md#writing-a-view-back) - writing a view back without building a tree
## Version history
File diff suppressed because one or more lines are too long
+7 -6
View File
@@ -7,7 +7,7 @@ string_t dump(const int indent = -1,
const number_format numbers = number_format::shortest) const;
```
Serializes this value (and its subtree) directly from the flat index, without ever building a `BasicJsonType` value first. With the default `numbers == number_format::shortest`, the result is the same string [`BasicJsonType::dump`](https://json.nlohmann.me/api/basic_json/dump/index.md) would produce for the value [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) builds from the same source text, called with the same `indent`, `indent_char`, and `ensure_ascii` -- except that members of an object appear in document order rather than sorted by key, and *every* occurrence of a repeated key is written rather than only the last one (see [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes)). For a `json_view` (whose `BasicJsonType` is not ordered), this means `dump()` can print an object's members in a different order than [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md)`.dump()` of the same subtree.
Serializes this value (and its subtree) directly from the flat index, without ever building a `BasicJsonType` value first. With the default `numbers == number_format::shortest`, the result is the same string [`BasicJsonType::dump`](https://json.nlohmann.me/api/basic_json/dump/index.md) would produce for the value [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) builds from the same source text, called with the same `indent`, `indent_char`, and `ensure_ascii` — except that members of an object appear in document order rather than sorted by key, and *every* occurrence of a repeated key is written rather than only the last one (see [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes)). For a `json_view` (whose `BasicJsonType` is not ordered), this means `dump()` can print an object's members in a different order than [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md)`.dump()` of the same subtree.
## Parameters
@@ -37,13 +37,13 @@ Linear in the size of the output text.
## Notes
The walk over the subtree is iterative, so the nesting depth it can write is limited by available memory only, not by the call stack -- as for [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md).
The walk over the subtree is iterative, so the nesting depth it can write is limited by available memory only, not by the call stack — as for [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md).
Strings are escaped by the same rules as [`BasicJsonType::dump`](https://json.nlohmann.me/api/basic_json/dump/index.md).
With `numbers == number_format::shortest`, floats are written with the library's shortest round-trip conversion, exactly as [`BasicJsonType::dump`](https://json.nlohmann.me/api/basic_json/dump/index.md) would (e.g. `1.5`, `100.0`, `1e+100`), and integers are copied from the source text -- already canonical in JSON, so this matches their shortest form too -- except that `-0` is written as `0`, the way [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) reads it.
With `numbers == number_format::shortest`, floats are written with the library's shortest round-trip conversion, exactly as [`BasicJsonType::dump`](https://json.nlohmann.me/api/basic_json/dump/index.md) would (e.g. `1.5`, `100.0`, `1e+100`), and integers are copied from the source text — already canonical in JSON, so this matches their shortest form too — except that `-0` is written as `0`, the way [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) reads it.
`number_format::source` copies every number exactly as written in the source text instead, with no exception for `-0` -- `1.50`, `1E2`, `-0.0`, `-0`, or all digits of an integer literal with more digits than any number type holds (such a literal is itself classified as a float, see [What is different](https://json.nlohmann.me/features/json_view/#what-is-different)) -- something `BasicJsonType` cannot do, since parsing already reduces every number to its parsed value.
`number_format::source` copies every number exactly as written in the source text instead, with no exception for `-0` — `1.50`, `1E2`, `-0.0`, `-0`, or all digits of an integer literal with more digits than any number type holds (such a literal is itself classified as a float, see [What is different](https://json.nlohmann.me/features/json_view/#what-is-different)) — something `BasicJsonType` cannot do, since parsing already reduces every number to its parsed value.
## Examples
@@ -101,9 +101,10 @@ Output:
## See also
- [`number_format`](https://json.nlohmann.me/api/basic_json_view/number_format/index.md) - how `dump()` writes numbers
- [operator\<<](https://json.nlohmann.me/api/basic_json_view/operator_ltlt/index.md) - serialize this value to a stream
- [materialize](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) - build a `BasicJsonType` value, e.g. to use `BasicJsonType::dump`'s `error_handler`
- [`operator<<`](https://json.nlohmann.me/api/basic_json_view/operator_ltlt/index.md) - serialize this value to a stream
- [`materialize`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) - build a `BasicJsonType` value, e.g. to use `BasicJsonType::dump`'s `error_handler`
- [`BasicJsonType::dump`](https://json.nlohmann.me/api/basic_json/dump/index.md) - the corresponding function of `basic_json`
- [Zero-copy JSON views](https://json.nlohmann.me/features/json_view/#writing-a-view-back) - writing a view back without building a tree
## Version history
+2 -2
View File
@@ -31,7 +31,7 @@ Constant.
## Notes
As for [`BasicJsonType::empty()`](../basic_json/empty.md), this does not return whether a string value is empty -- it
As for [`BasicJsonType::empty()`](../basic_json/empty.md), this does not return whether a string value is empty — it
is `#!cpp false` for any string, regardless of its length.
## Examples
@@ -78,7 +78,7 @@ is `#!cpp false` for any string, regardless of its length.
## See also
- [size](size.md) - return the number of elements
- [`size`](size.md) - return the number of elements
- [`BasicJsonType::empty`](../basic_json/empty.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -30,7 +30,7 @@ Constant.
## Notes
As for [`BasicJsonType::empty()`](https://json.nlohmann.me/api/basic_json/empty/index.md), this does not return whether a string value is empty -- it is `false` for any string, regardless of its length.
As for [`BasicJsonType::empty()`](https://json.nlohmann.me/api/basic_json/empty/index.md), this does not return whether a string value is empty — it is `false` for any string, regardless of its length.
## Examples
@@ -73,7 +73,7 @@ true 0
## See also
- [size](https://json.nlohmann.me/api/basic_json_view/size/index.md) - return the number of elements
- [`size`](https://json.nlohmann.me/api/basic_json_view/size/index.md) - return the number of elements
- [`BasicJsonType::empty`](https://json.nlohmann.me/api/basic_json/empty/index.md) - the corresponding function of `basic_json`
## Version history
+3 -3
View File
@@ -5,7 +5,7 @@ iterator end() const noexcept;
```
Returns an iterator to one past the last element of an array, one past the last member value of an object, in
**document order** -- see [`begin()`](begin.md). A primitive value iterates as a range of one element (itself), and a
**document order** — see [`begin()`](begin.md). A primitive value iterates as a range of one element (itself), and a
`#!json null` value or a [discarded](is_discarded.md) view iterates as an empty range (`#!cpp begin() == end()`).
## Return value
@@ -72,8 +72,8 @@ way to reach the last element by stepping back from `end()`. Use [`back()`](back
## See also
- [begin](begin.md) - returns an iterator to the first element
- [cend](cend.md) - returns a const iterator to one past the last element
- [`begin`](begin.md) - returns an iterator to the first element
- [`cend`](cend.md) - returns a const iterator to one past the last element
- [`BasicJsonType::end`](../basic_json/end.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -4,7 +4,7 @@
iterator end() const noexcept;
```
Returns an iterator to one past the last element of an array, one past the last member value of an object, in **document order** -- see [`begin()`](https://json.nlohmann.me/api/basic_json_view/begin/index.md). A primitive value iterates as a range of one element (itself), and a `null` value or a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view iterates as an empty range (`begin() == end()`).
Returns an iterator to one past the last element of an array, one past the last member value of an object, in **document order** — see [`begin()`](https://json.nlohmann.me/api/basic_json_view/begin/index.md). A primitive value iterates as a range of one element (itself), and a `null` value or a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view iterates as an empty range (`begin() == end()`).
## Return value
@@ -66,8 +66,8 @@ first reading over 20: 25
## See also
- [begin](https://json.nlohmann.me/api/basic_json_view/begin/index.md) - returns an iterator to the first element
- [cend](https://json.nlohmann.me/api/basic_json_view/cend/index.md) - returns a const iterator to one past the last element
- [`begin`](https://json.nlohmann.me/api/basic_json_view/begin/index.md) - returns an iterator to the first element
- [`cend`](https://json.nlohmann.me/api/basic_json_view/cend/index.md) - returns a const iterator to one past the last element
- [`BasicJsonType::end`](https://json.nlohmann.me/api/basic_json/end/index.md) - the corresponding function of `basic_json`
## Version history
+5 -5
View File
@@ -6,7 +6,7 @@ iterator find(const char* key) const;
iterator find(const string_t& key) const;
```
Finds a member with key `key` -- the first one, should the key occur more than once (see
Finds a member with key `key` — the first one, should the key occur more than once (see
[Notes on duplicate keys](operator[].md#notes)). If the value is not an object, or no member has this key,
[`end()`](end.md) is returned.
@@ -27,7 +27,7 @@ No-throw guarantee: this function never throws exceptions.
Linear in the number of members: as for [`ordered_json`](../ordered_json.md), members are compared one after another,
in document order, stopping at the first match. Each comparison first checks the key's length
-- already known from the index, without reading the key bytes -- before comparing its content.
— already known from the index, without reading the key bytes — before comparing its content.
Objects with 128 or more members get a hash index of their keys while parsing, so that a lookup in them takes
constant time on average.
@@ -41,7 +41,7 @@ constant time on average.
the last value.
Unlike [`BasicJsonType::find`](../basic_json/find.md), which always returns `#!cpp end()` for a non-object type, this
also does so for a [discarded](is_discarded.md) view -- there is no separate "invalid" iterator to return.
also does so for a [discarded](is_discarded.md) view — there is no separate "invalid" iterator to return.
## Examples
@@ -94,8 +94,8 @@ also does so for a [discarded](is_discarded.md) view -- there is no separate "in
## See also
- [count](count.md) - returns the number of occurrences of a key
- [contains](contains.md) - checks whether a key exists
- [`count`](count.md) - returns the number of occurrences of a key
- [`contains`](contains.md) - checks whether a key exists
- [`BasicJsonType::find`](../basic_json/find.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+5 -5
View File
@@ -6,7 +6,7 @@ iterator find(const char* key) const;
iterator find(const string_t& key) const;
```
Finds a member with key `key` -- the first one, should the key occur more than once (see [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes)). If the value is not an object, or no member has this key, [`end()`](https://json.nlohmann.me/api/basic_json_view/end/index.md) is returned.
Finds a member with key `key` — the first one, should the key occur more than once (see [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes)). If the value is not an object, or no member has this key, [`end()`](https://json.nlohmann.me/api/basic_json_view/end/index.md) is returned.
## Parameters
@@ -22,7 +22,7 @@ No-throw guarantee: this function never throws exceptions.
## Complexity
Linear in the number of members: as for [`ordered_json`](https://json.nlohmann.me/api/ordered_json/index.md), members are compared one after another, in document order, stopping at the first match. Each comparison first checks the key's length -- already known from the index, without reading the key bytes -- before comparing its content. Objects with 128 or more members get a hash index of their keys while parsing, so that a lookup in them takes constant time on average.
Linear in the number of members: as for [`ordered_json`](https://json.nlohmann.me/api/ordered_json/index.md), members are compared one after another, in document order, stopping at the first match. Each comparison first checks the key's length — already known from the index, without reading the key bytes — before comparing its content. Objects with 128 or more members get a hash index of their keys while parsing, so that a lookup in them takes constant time on average.
## Notes
@@ -30,7 +30,7 @@ Duplicate keys: the first member wins
If the source text repeats a key, this resolves to the *first* member with it, not to the last one that [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) and `parse()` keep. See the [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes) of `operator[]` and [Duplicate keys](https://json.nlohmann.me/features/json_view/#duplicate-keys) for the reasons and for how to get the last value.
Unlike [`BasicJsonType::find`](https://json.nlohmann.me/api/basic_json/find/index.md), which always returns `end()` for a non-object type, this also does so for a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view -- there is no separate "invalid" iterator to return.
Unlike [`BasicJsonType::find`](https://json.nlohmann.me/api/basic_json/find/index.md), which always returns `end()` for a non-object type, this also does so for a [discarded](https://json.nlohmann.me/api/basic_json_view/is_discarded/index.md) view — there is no separate "invalid" iterator to return.
## Examples
@@ -79,8 +79,8 @@ user 7
## See also
- [count](https://json.nlohmann.me/api/basic_json_view/count/index.md) - returns the number of occurrences of a key
- [contains](https://json.nlohmann.me/api/basic_json_view/contains/index.md) - checks whether a key exists
- [`count`](https://json.nlohmann.me/api/basic_json_view/count/index.md) - returns the number of occurrences of a key
- [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md) - checks whether a key exists
- [`BasicJsonType::find`](https://json.nlohmann.me/api/basic_json/find/index.md) - the corresponding function of `basic_json`
## Version history
+1 -1
View File
@@ -79,7 +79,7 @@ view.
## See also
- [back](back.md) - access the last element
- [`back`](back.md) - access the last element
- [`BasicJsonType::front`](../basic_json/front.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -70,7 +70,7 @@ Output:
## See also
- [back](https://json.nlohmann.me/api/basic_json_view/back/index.md) - access the last element
- [`back`](https://json.nlohmann.me/api/basic_json_view/back/index.md) - access the last element
- [`BasicJsonType::front`](https://json.nlohmann.me/api/basic_json/front/index.md) - the corresponding function of `basic_json`
## Version history
+18 -17
View File
@@ -7,26 +7,26 @@ T get() const;
Converts the value to `T`.
For the types below, the conversion works directly on the flat index -- no `BasicJsonType` value is built for it:
For the types below, the conversion works directly on the flat index — no `BasicJsonType` value is built for it:
- `#!cpp bool`
- arithmetic types other than `#!cpp bool` (for a boolean, `#!cpp 0`/`#!cpp 1`, exactly as for
[`BasicJsonType::get<T>()`](../basic_json/get.md))
- `#!cpp std::nullptr_t`
- `#!cpp std::basic_string<char, Traits, Alloc>` (including `string_t`) -- a copy of the string
- [`string_view_t`](index.md#member-types) -- **no copy**: the returned view points into the document's
- `#!cpp std::basic_string<char, Traits, Alloc>` (including `string_t`) — a copy of the string
- [`string_view_t`](index.md#member-types) — **no copy**: the returned view points into the document's
[`source()`](../basic_json_document/source.md) text, or, for a string that contains escape sequences, into the
document's own buffer of decoded strings (see [`get_string()`](get_string.md))
- `BasicJsonType` -- equivalent to [`materialize()`](materialize.md)
- `basic_json_view` -- returns `#!cpp *this`
- `#!cpp std::vector<U, A>` of the types above -- from an array, element by element, each converted with
- `BasicJsonType` — equivalent to [`materialize()`](materialize.md)
- `basic_json_view` — returns `#!cpp *this`
- `#!cpp std::vector<U, A>` of the types above — from an array, element by element, each converted with
`#!cpp get<U>()`; `#!cpp std::vector<basic_json_view>` keeps a view of every element instead of a value
- `#!cpp std::map<K, basic_json_view, C, A>` and `#!cpp std::unordered_map<K, basic_json_view, H, E, A>`, if `K` is
constructible from a `#!cpp (const char*, std::size_t)` pair -- views of the members of an object; with a repeated
constructible from a `#!cpp (const char*, std::size_t)` pair — views of the members of an object; with a repeated
key, the view of the *last* member is kept, as [`BasicJsonType::parse()`](../basic_json/parse.md) keeps its value
A default-constructible `T` whose `from_json()` accepts views reads the view directly as well, without building a
`BasicJsonType` value. This covers the library's own conversions of the standard library types -- all other
`BasicJsonType` value. This covers the library's own conversions of the standard library types — all other
`#!cpp std::vector`s, `#!cpp std::map`/`#!cpp std::unordered_map` (also with other key types), `#!cpp std::list`,
`#!cpp std::deque`, `#!cpp std::set`, `#!cpp std::forward_list`, `#!cpp std::valarray`, `#!cpp std::array`, C arrays,
`#!cpp std::pair`, `#!cpp std::tuple`, `#!cpp std::optional`, enumerations, `#!cpp std::filesystem::path`, ... --
@@ -47,8 +47,8 @@ T&)` of [arbitrary type conversions](../../features/arbitrary_types.md), is not
keeps it: for `#!cpp {"x":1,"x":2}`, `#!cpp get<point>()` reads `#!cpp x == 1`. See
[Duplicate keys](../../features/json_view.md#duplicate-keys).
Every other `T` -- user types whose `from_json()` is written for `BasicJsonType` only, types without a default
constructor, `#!cpp std::tuple`s holding references, ... -- is converted by `#!cpp materialize().get<T>()`: the subtree is built into a real `BasicJsonType`
Every other `T` — user types whose `from_json()` is written for `BasicJsonType` only, types without a default
constructor, `#!cpp std::tuple`s holding references, ... — is converted by `#!cpp materialize().get<T>()`: the subtree is built into a real `BasicJsonType`
value first (as [`BasicJsonType::parse()`](../basic_json/parse.md) would), and converted from there exactly as
[`BasicJsonType::get<T>()`](../basic_json/get.md) would convert it.
@@ -69,7 +69,7 @@ Strong guarantee: there are no changes to the view or the document it refers to.
- For the directly-converted types listed above (other than `BasicJsonType` and `basic_json_view`, which never
throw): throws [`type_error.302`](../../home/exceptions.md#jsonexceptiontype_error302) if the value's type does not
match `T` -- the same exception, with the same message, that [`BasicJsonType::get<T>()`](../basic_json/get.md)
match `T` — the same exception, with the same message, that [`BasicJsonType::get<T>()`](../basic_json/get.md)
throws for the same JSON type and `T`.
- For `#!cpp std::vector<U, A>`: throws `type_error.302` if the value is not an array; otherwise, whatever converting
an element to `U` throws.
@@ -77,7 +77,7 @@ Strong guarantee: there are no changes to the view or the document it refers to.
- For a `T` whose `from_json()` reads the view: whatever that `from_json()` throws; for the library's conversions and
the macros, the same exceptions with the same messages as [`BasicJsonType::get<T>()`](../basic_json/get.md) of the
same value.
- For every other `T`: whatever [`materialize().get<T>()`](../basic_json/get.md) throws -- typically `type_error.302`,
- For every other `T`: whatever [`materialize().get<T>()`](../basic_json/get.md) throws — typically `type_error.302`,
or whatever a user-provided `from_json()` throws.
None of the exceptions thrown directly by this function or by a `from_json()` that reads the view (the first four
@@ -132,7 +132,7 @@ document.
The example below reads typed fields straight into C++ variables, collects a view of every array element with
`#!cpp get<std::vector<basic_json_view>>()` instead of a value, and converts a nested object into a user type
through its `from_json()` -- which runs on a `BasicJsonType` value `materialize()` builds for just that one
through its `from_json()` — which runs on a `BasicJsonType` value `materialize()` builds for just that one
member.
```cpp
@@ -205,11 +205,12 @@ document.
## See also
- [get_to](get_to.md) - convert and write into a passed value
- [get_string](get_string.md) - the string, without a copy
- [number_token](number_token.md) - a number's token text, without a copy
- [materialize](materialize.md) - build the `BasicJsonType` value of this subtree
- [`get_to`](get_to.md) - convert and write into a passed value
- [`get_string`](get_string.md) - the string, without a copy
- [`number_token`](number_token.md) - a number's token text, without a copy
- [`materialize`](materialize.md) - build the `BasicJsonType` value of this subtree
- [`BasicJsonType::get`](../basic_json/get.md) - the corresponding function of `basic_json`
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - which conversions avoid building a basic_json value
## Version history
File diff suppressed because one or more lines are too long
+17 -16
View File
@@ -7,25 +7,25 @@ T get() const;
Converts the value to `T`.
For the types below, the conversion works directly on the flat index -- no `BasicJsonType` value is built for it:
For the types below, the conversion works directly on the flat index — no `BasicJsonType` value is built for it:
- `bool`
- arithmetic types other than `bool` (for a boolean, `0`/`1`, exactly as for [`BasicJsonType::get<T>()`](https://json.nlohmann.me/api/basic_json/get/index.md))
- `std::nullptr_t`
- `std::basic_string<char, Traits, Alloc>` (including `string_t`) -- a copy of the string
- [`string_view_t`](https://json.nlohmann.me/api/basic_json_view/#member-types) -- **no copy**: the returned view points into the document's [`source()`](https://json.nlohmann.me/api/basic_json_document/source/index.md) text, or, for a string that contains escape sequences, into the document's own buffer of decoded strings (see [`get_string()`](https://json.nlohmann.me/api/basic_json_view/get_string/index.md))
- `BasicJsonType` -- equivalent to [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md)
- `basic_json_view` -- returns `*this`
- `std::vector<U, A>` of the types above -- from an array, element by element, each converted with `get<U>()`; `std::vector<basic_json_view>` keeps a view of every element instead of a value
- `std::map<K, basic_json_view, C, A>` and `std::unordered_map<K, basic_json_view, H, E, A>`, if `K` is constructible from a `(const char*, std::size_t)` pair -- views of the members of an object; with a repeated key, the view of the *last* member is kept, as [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) keeps its value
- `std::basic_string<char, Traits, Alloc>` (including `string_t`) — a copy of the string
- [`string_view_t`](https://json.nlohmann.me/api/basic_json_view/#member-types) — **no copy**: the returned view points into the document's [`source()`](https://json.nlohmann.me/api/basic_json_document/source/index.md) text, or, for a string that contains escape sequences, into the document's own buffer of decoded strings (see [`get_string()`](https://json.nlohmann.me/api/basic_json_view/get_string/index.md))
- `BasicJsonType` — equivalent to [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md)
- `basic_json_view` — returns `*this`
- `std::vector<U, A>` of the types above — from an array, element by element, each converted with `get<U>()`; `std::vector<basic_json_view>` keeps a view of every element instead of a value
- `std::map<K, basic_json_view, C, A>` and `std::unordered_map<K, basic_json_view, H, E, A>`, if `K` is constructible from a `(const char*, std::size_t)` pair — views of the members of an object; with a repeated key, the view of the *last* member is kept, as [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) keeps its value
A default-constructible `T` whose `from_json()` accepts views reads the view directly as well, without building a `BasicJsonType` value. This covers the library's own conversions of the standard library types -- all other `std::vector`s, `std::map`/`std::unordered_map` (also with other key types), `std::list`, `std::deque`, `std::set`, `std::forward_list`, `std::valarray`, `std::array`, C arrays, `std::pair`, `std::tuple`, `std::optional`, enumerations, `std::filesystem::path`, ... -- which give the same values as `materialize().get<T>()` (from an object, a repeated key keeps the *last* value, as [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) does), as well as the types of the [`NLOHMANN_DEFINE_TYPE_*`](https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/index.md) and [`NLOHMANN_DEFINE_DERIVED_TYPE_*`](https://json.nlohmann.me/api/macros/nlohmann_define_derived_type/index.md) macros and the enumerations of [`NLOHMANN_JSON_SERIALIZE_ENUM`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum/index.md), and any `from_json()` constrained to accept views, e.g. with [`is_json_view`](https://json.nlohmann.me/api/is_json_view/index.md). A `from_json()` that also accepts types that are no JSON values at all, such as the unconstrained `template<typename BasicJsonType> void from_json(const BasicJsonType&,T&)` of [arbitrary type conversions](https://json.nlohmann.me/features/arbitrary_types/index.md), is not called with a view: it may use `BasicJsonType` functions a view does not have. See [Writing generic code](https://json.nlohmann.me/features/json_view/#writing-generic-code).
A default-constructible `T` whose `from_json()` accepts views reads the view directly as well, without building a `BasicJsonType` value. This covers the library's own conversions of the standard library types — all other `std::vector`s, `std::map`/`std::unordered_map` (also with other key types), `std::list`, `std::deque`, `std::set`, `std::forward_list`, `std::valarray`, `std::array`, C arrays, `std::pair`, `std::tuple`, `std::optional`, enumerations, `std::filesystem::path`, ... -- which give the same values as `materialize().get<T>()` (from an object, a repeated key keeps the *last* value, as [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) does), as well as the types of the [`NLOHMANN_DEFINE_TYPE_*`](https://json.nlohmann.me/api/macros/nlohmann_define_type_intrusive/index.md) and [`NLOHMANN_DEFINE_DERIVED_TYPE_*`](https://json.nlohmann.me/api/macros/nlohmann_define_derived_type/index.md) macros and the enumerations of [`NLOHMANN_JSON_SERIALIZE_ENUM`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum/index.md), and any `from_json()` constrained to accept views, e.g. with [`is_json_view`](https://json.nlohmann.me/api/is_json_view/index.md). A `from_json()` that also accepts types that are no JSON values at all, such as the unconstrained `template<typename BasicJsonType> void from_json(const BasicJsonType&,T&)` of [arbitrary type conversions](https://json.nlohmann.me/features/arbitrary_types/index.md), is not called with a view: it may use `BasicJsonType` functions a view does not have. See [Writing generic code](https://json.nlohmann.me/features/json_view/#writing-generic-code).
Duplicate keys
Such a `from_json()` looks members up in the view, where a repeated key finds the **first** member, while `materialize().get<T>()` sees the **last** one, as [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) keeps it: for `{"x":1,"x":2}`, `get<point>()` reads `x == 1`. See [Duplicate keys](https://json.nlohmann.me/features/json_view/#duplicate-keys).
Every other `T` -- user types whose `from_json()` is written for `BasicJsonType` only, types without a default constructor, `std::tuple`s holding references, ... -- is converted by `materialize().get<T>()`: the subtree is built into a real `BasicJsonType` value first (as [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) would), and converted from there exactly as [`BasicJsonType::get<T>()`](https://json.nlohmann.me/api/basic_json/get/index.md) would convert it.
Every other `T` — user types whose `from_json()` is written for `BasicJsonType` only, types without a default constructor, `std::tuple`s holding references, ... — is converted by `materialize().get<T>()`: the subtree is built into a real `BasicJsonType` value first (as [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) would), and converted from there exactly as [`BasicJsonType::get<T>()`](https://json.nlohmann.me/api/basic_json/get/index.md) would convert it.
## Template parameters
@@ -41,11 +41,11 @@ Strong guarantee: there are no changes to the view or the document it refers to.
## Exceptions
- For the directly-converted types listed above (other than `BasicJsonType` and `basic_json_view`, which never throw): throws [`type_error.302`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error302) if the value's type does not match `T` -- the same exception, with the same message, that [`BasicJsonType::get<T>()`](https://json.nlohmann.me/api/basic_json/get/index.md) throws for the same JSON type and `T`.
- For the directly-converted types listed above (other than `BasicJsonType` and `basic_json_view`, which never throw): throws [`type_error.302`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error302) if the value's type does not match `T` — the same exception, with the same message, that [`BasicJsonType::get<T>()`](https://json.nlohmann.me/api/basic_json/get/index.md) throws for the same JSON type and `T`.
- For `std::vector<U, A>`: throws `type_error.302` if the value is not an array; otherwise, whatever converting an element to `U` throws.
- For `std::map`/`std::unordered_map` of views: throws `type_error.302` if the value is not an object.
- For a `T` whose `from_json()` reads the view: whatever that `from_json()` throws; for the library's conversions and the macros, the same exceptions with the same messages as [`BasicJsonType::get<T>()`](https://json.nlohmann.me/api/basic_json/get/index.md) of the same value.
- For every other `T`: whatever [`materialize().get<T>()`](https://json.nlohmann.me/api/basic_json/get/index.md) throws -- typically `type_error.302`, or whatever a user-provided `from_json()` throws.
- For every other `T`: whatever [`materialize().get<T>()`](https://json.nlohmann.me/api/basic_json/get/index.md) throws — typically `type_error.302`, or whatever a user-provided `from_json()` throws.
None of the exceptions thrown directly by this function or by a `from_json()` that reads the view (the first four bullets above) carry a [`JSON_DIAGNOSTICS`](https://json.nlohmann.me/api/macros/json_diagnostics/index.md) path: the view has no `BasicJsonType` value to point at. An exception thrown while converting through `materialize()` (the last bullet) is different: it is thrown by a real `BasicJsonType` value, so it **does** carry a `JSON_DIAGNOSTICS` path if `BasicJsonType` was built with it enabled. That path is relative to the root of the view's subtree, because `materialize()` builds only the subtree (with parent pointers): it is empty if the failing value is the subtree's root itself, and it never is the path within the whole document.
@@ -77,7 +77,7 @@ Unlike `BasicJsonType`, `basic_json_view` has no stored value anywhere to hand o
Example
The example below reads typed fields straight into C++ variables, collects a view of every array element with `get<std::vector<basic_json_view>>()` instead of a value, and converts a nested object into a user type through its `from_json()` -- which runs on a `BasicJsonType` value `materialize()` builds for just that one member.
The example below reads typed fields straight into C++ variables, collects a view of every array element with `get<std::vector<basic_json_view>>()` instead of a value, and converts a nested object into a user type through its `from_json()` — which runs on a `BasicJsonType` value `materialize()` builds for just that one member.
```
#include <iostream>
@@ -147,11 +147,12 @@ Berlin 10115
## See also
- [get_to](https://json.nlohmann.me/api/basic_json_view/get_to/index.md) - convert and write into a passed value
- [get_string](https://json.nlohmann.me/api/basic_json_view/get_string/index.md) - the string, without a copy
- [number_token](https://json.nlohmann.me/api/basic_json_view/number_token/index.md) - a number's token text, without a copy
- [materialize](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) - build the `BasicJsonType` value of this subtree
- [`get_to`](https://json.nlohmann.me/api/basic_json_view/get_to/index.md) - convert and write into a passed value
- [`get_string`](https://json.nlohmann.me/api/basic_json_view/get_string/index.md) - the string, without a copy
- [`number_token`](https://json.nlohmann.me/api/basic_json_view/number_token/index.md) - a number's token text, without a copy
- [`materialize`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) - build the `BasicJsonType` value of this subtree
- [`BasicJsonType::get`](https://json.nlohmann.me/api/basic_json/get/index.md) - the corresponding function of `basic_json`
- [Zero-copy JSON views](https://json.nlohmann.me/features/json_view/#getting-values-out-without-copying) - which conversions avoid building a basic_json value
## Version history
+7 -6
View File
@@ -41,8 +41,8 @@ counterpart, except that it returns a view instead of a reference to a value tha
document, the returned [`string_view_t`](index.md#member-types) is valid as long as the caller's buffer; for an owned
one, as long as the document.
The returned [`string_view_t`](index.md#member-types) is valid exactly as long as the view that produced it -- see the
[validity rules](index.md) of `basic_json_view` -- and, for a string with no escapes, for as long as the document's
The returned [`string_view_t`](index.md#member-types) is valid exactly as long as the view that produced it — see the
[validity rules](index.md) of `basic_json_view` — and, for a string with no escapes, for as long as the document's
source text, which for a borrowed document must remain valid **and unmodified** for as long as the document exists,
since floating-point values and unescaped strings are read from the source lazily.
@@ -52,8 +52,8 @@ since floating-point values and unescaped strings are read from the source lazil
The example below pulls one field out of a JSON text that stands in for a large API response, and shows that no
`#!cpp std::string` was allocated for it: the returned view still points inside the original buffer. A field that
contains an escape sequence cannot point into the original text -- it was decoded once into the document's own
buffer instead -- but still avoids a per-field allocation.
contains an escape sequence cannot point into the original text — it was decoded once into the document's own
buffer instead — but still avoids a per-field allocation.
```cpp
#include <iostream>
@@ -101,9 +101,10 @@ since floating-point values and unescaped strings are read from the source lazil
## See also
- [get](get.md) - convert the value to a given type (`#!cpp get<string_view_t>()` is equivalent to this function)
- [number_token](number_token.md) - a number's token text, without a copy
- [`get`](get.md) - convert the value to a given type (`#!cpp get<string_view_t>()` is equivalent to this function)
- [`number_token`](number_token.md) - a number's token text, without a copy
- [`BasicJsonType::get_ref`](../basic_json/get_ref.md) - the closest counterpart of `basic_json`
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - borrowing strings instead of copying them
## Version history
File diff suppressed because one or more lines are too long
+5 -4
View File
@@ -30,13 +30,13 @@ Constant.
`get_string()` borrows the string: nothing is copied, whereas [`get<std::string>()`](https://json.nlohmann.me/api/basic_json_view/get/index.md) copies it. For a borrowed document, the returned [`string_view_t`](https://json.nlohmann.me/api/basic_json_view/#member-types) is valid as long as the caller's buffer; for an owned one, as long as the document.
The returned [`string_view_t`](https://json.nlohmann.me/api/basic_json_view/#member-types) is valid exactly as long as the view that produced it -- see the [validity rules](https://json.nlohmann.me/api/basic_json_view/index.md) of `basic_json_view` -- and, for a string with no escapes, for as long as the document's source text, which for a borrowed document must remain valid **and unmodified** for as long as the document exists, since floating-point values and unescaped strings are read from the source lazily.
The returned [`string_view_t`](https://json.nlohmann.me/api/basic_json_view/#member-types) is valid exactly as long as the view that produced it — see the [validity rules](https://json.nlohmann.me/api/basic_json_view/index.md) of `basic_json_view` — and, for a string with no escapes, for as long as the document's source text, which for a borrowed document must remain valid **and unmodified** for as long as the document exists, since floating-point values and unescaped strings are read from the source lazily.
## Examples
Example
The example below pulls one field out of a JSON text that stands in for a large API response, and shows that no `std::string` was allocated for it: the returned view still points inside the original buffer. A field that contains an escape sequence cannot point into the original text -- it was decoded once into the document's own buffer instead -- but still avoids a per-field allocation.
The example below pulls one field out of a JSON text that stands in for a large API response, and shows that no `std::string` was allocated for it: the returned view still points inside the original buffer. A field that contains an escape sequence cannot point into the original text — it was decoded once into the document's own buffer instead — but still avoids a per-field allocation.
```
#include <iostream>
@@ -82,9 +82,10 @@ false
## See also
- [get](https://json.nlohmann.me/api/basic_json_view/get/index.md) - convert the value to a given type (`get<string_view_t>()` is equivalent to this function)
- [number_token](https://json.nlohmann.me/api/basic_json_view/number_token/index.md) - a number's token text, without a copy
- [`get`](https://json.nlohmann.me/api/basic_json_view/get/index.md) - convert the value to a given type (`get<string_view_t>()` is equivalent to this function)
- [`number_token`](https://json.nlohmann.me/api/basic_json_view/number_token/index.md) - a number's token text, without a copy
- [`BasicJsonType::get_ref`](https://json.nlohmann.me/api/basic_json/get_ref/index.md) - the closest counterpart of `basic_json`
- [Zero-copy JSON views](https://json.nlohmann.me/features/json_view/#getting-values-out-without-copying) - borrowing strings instead of copying them
## Version history
+4 -3
View File
@@ -7,9 +7,9 @@ T& get_to(T& v) const;
Converts the value to `T` and stores it in `v`, in one of three ways:
- For the types that [`get<T>()`](get.md) converts directly -- arithmetic types, `#!cpp bool`,
- For the types that [`get<T>()`](get.md) converts directly — arithmetic types, `#!cpp bool`,
`#!cpp std::nullptr_t`, [`string_view_t`](index.md#member-types), `#!cpp std::basic_string`, `BasicJsonType`,
`basic_json_view`, vectors of these, and maps of views -- `v` is assigned: `#!cpp v = get<T>()`.
`basic_json_view`, vectors of these, and maps of views — `v` is assigned: `#!cpp v = get<T>()`.
- For a type whose `from_json()` accepts views (see [`get<T>()`](get.md)), that `from_json()` is called with the
view and the existing `v`, without building a `BasicJsonType` value.
- For every other type, the subtree is built into a `BasicJsonType` value and `#!cpp materialize().get_to(v)` is
@@ -103,8 +103,9 @@ them with those of a default-constructed `T`.
## See also
- [get](get.md) - convert the value to a given type
- [`get`](get.md) - convert the value to a given type
- [`BasicJsonType::get_to`](../basic_json/get_to.md) - the corresponding function of `basic_json`
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - which conversions avoid building a basic_json value
## Version history
File diff suppressed because one or more lines are too long
+3 -2
View File
@@ -7,7 +7,7 @@ T& get_to(T& v) const;
Converts the value to `T` and stores it in `v`, in one of three ways:
- For the types that [`get<T>()`](https://json.nlohmann.me/api/basic_json_view/get/index.md) converts directly -- arithmetic types, `bool`, `std::nullptr_t`, [`string_view_t`](https://json.nlohmann.me/api/basic_json_view/#member-types), `std::basic_string`, `BasicJsonType`, `basic_json_view`, vectors of these, and maps of views -- `v` is assigned: `v = get<T>()`.
- For the types that [`get<T>()`](https://json.nlohmann.me/api/basic_json_view/get/index.md) converts directly — arithmetic types, `bool`, `std::nullptr_t`, [`string_view_t`](https://json.nlohmann.me/api/basic_json_view/#member-types), `std::basic_string`, `BasicJsonType`, `basic_json_view`, vectors of these, and maps of views — `v` is assigned: `v = get<T>()`.
- For a type whose `from_json()` accepts views (see [`get<T>()`](https://json.nlohmann.me/api/basic_json_view/get/index.md)), that `from_json()` is called with the view and the existing `v`, without building a `BasicJsonType` value.
- For every other type, the subtree is built into a `BasicJsonType` value and `materialize().get_to(v)` is called, i.e. `from_json()` is invoked with the existing `v`, exactly as [`BasicJsonType::get_to()`](https://json.nlohmann.me/api/basic_json/get_to/index.md) does.
@@ -88,8 +88,9 @@ db.example.com:5432 (tls)
## See also
- [get](https://json.nlohmann.me/api/basic_json_view/get/index.md) - convert the value to a given type
- [`get`](https://json.nlohmann.me/api/basic_json_view/get/index.md) - convert the value to a given type
- [`BasicJsonType::get_to`](https://json.nlohmann.me/api/basic_json/get_to/index.md) - the corresponding function of `basic_json`
- [Zero-copy JSON views](https://json.nlohmann.me/features/json_view/#getting-values-out-without-copying) - which conversions avoid building a basic_json value
## Version history
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -26,7 +26,7 @@ Moving the document itself does not invalidate its views: the index is heap-allo
[`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md), [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md), and [`value`](https://json.nlohmann.me/api/basic_json_view/value/index.md) also accept a [`json_pointer`](https://json.nlohmann.me/api/json_pointer/index.md). Unlike `basic_json`, there are no implicit conversion operators (no `operator ValueType()`), and no `get_ptr()` or `get_ref()`; see [`get`](https://json.nlohmann.me/api/basic_json_view/get/index.md).
`basic_json_view` itself is always read-only -- it never has a `set` or `push_back` of its own. A view of an **editable** document (`view_mode::editable`) sees every edit made through [`basic_json_document::set`](https://json.nlohmann.me/api/basic_json_document/set/index.md) and [`basic_json_document::push_back`](https://json.nlohmann.me/api/basic_json_document/push_back/index.md): once a value is changed, every view that still refers to it -- including ones taken before the change -- reads the new value. See [Edits](https://json.nlohmann.me/api/basic_json_document/#edits).
`basic_json_view` itself is always read-only — it never has a `set` or `push_back` of its own. A view of an **editable** document (`view_mode::editable`) sees every edit made through [`basic_json_document::set`](https://json.nlohmann.me/api/basic_json_document/set/index.md) and [`basic_json_document::push_back`](https://json.nlohmann.me/api/basic_json_document/push_back/index.md): once a value is changed, every view that still refers to it — including ones taken before the change — reads the new value. See [Edits](https://json.nlohmann.me/api/basic_json_document/#edits).
## Template parameters
@@ -125,9 +125,9 @@ Moving the document itself does not invalidate its views: the index is heap-allo
## See also
- [Zero-copy JSON views](https://json.nlohmann.me/features/json_view/index.md) - guide to documents and views
- [**basic_json_document**](https://json.nlohmann.me/api/basic_json_document/index.md) - the document that owns the parsed data
- [**json_view**](https://json.nlohmann.me/api/json_view/index.md) and [**json_editable_view**](https://json.nlohmann.me/api/json_editable_view/index.md) - the default specializations
- [**materialize**](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) - build a `basic_json` value from a view
- [`basic_json_document`](https://json.nlohmann.me/api/basic_json_document/index.md) - the document that owns the parsed data
- [`json_view`](https://json.nlohmann.me/api/json_view/index.md) - and [`json_editable_view`](https://json.nlohmann.me/api/json_editable_view/index.md) - the default specializations
- [`materialize`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) - build a `basic_json` value from a view
## Version history
+3 -3
View File
@@ -92,9 +92,9 @@ Constant.
## See also
- [is_structured](is_structured.md) - return whether the type is structured
- [size](size.md) - the number of elements
- [empty](empty.md) - whether there are no elements
- [`is_structured`](is_structured.md) - return whether the type is structured
- [`size`](size.md) - the number of elements
- [`empty`](empty.md) - whether there are no elements
- [`BasicJsonType::is_array`](../basic_json/is_array.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -89,9 +89,9 @@ true
## See also
- [is_structured](https://json.nlohmann.me/api/basic_json_view/is_structured/index.md) - return whether the type is structured
- [size](https://json.nlohmann.me/api/basic_json_view/size/index.md) - the number of elements
- [empty](https://json.nlohmann.me/api/basic_json_view/empty/index.md) - whether there are no elements
- [`is_structured`](https://json.nlohmann.me/api/basic_json_view/is_structured/index.md) - return whether the type is structured
- [`size`](https://json.nlohmann.me/api/basic_json_view/size/index.md) - the number of elements
- [`empty`](https://json.nlohmann.me/api/basic_json_view/empty/index.md) - whether there are no elements
- [`BasicJsonType::is_array`](https://json.nlohmann.me/api/basic_json/is_array/index.md) - the corresponding function of `basic_json`
## Version history
+1 -1
View File
@@ -94,7 +94,7 @@ Constant.
## See also
- [type](type.md) - return the type of the value
- [`type`](type.md) - return the type of the value
- [`BasicJsonType::is_binary`](../basic_json/is_binary.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -89,7 +89,7 @@ true
## See also
- [type](https://json.nlohmann.me/api/basic_json_view/type/index.md) - return the type of the value
- [`type`](https://json.nlohmann.me/api/basic_json_view/type/index.md) - return the type of the value
- [`BasicJsonType::is_binary`](https://json.nlohmann.me/api/basic_json/is_binary/index.md) - the corresponding function of `basic_json`
## Version history
+1 -1
View File
@@ -92,7 +92,7 @@ Constant.
## See also
- [type](type.md) - return the type of the value
- [`type`](type.md) - return the type of the value
- [`BasicJsonType::is_boolean`](../basic_json/is_boolean.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -89,7 +89,7 @@ true
## See also
- [type](https://json.nlohmann.me/api/basic_json_view/type/index.md) - return the type of the value
- [`type`](https://json.nlohmann.me/api/basic_json_view/type/index.md) - return the type of the value
- [`BasicJsonType::is_boolean`](https://json.nlohmann.me/api/basic_json/is_boolean/index.md) - the corresponding function of `basic_json`
## Version history
+5 -4
View File
@@ -6,7 +6,7 @@ bool is_discarded() const noexcept;
Returns whether this view is invalid, i.e. does not refer to a value. This is the case for a default-constructed
view (see [(constructor)](basic_json_view.md)), and for [`root()`](../basic_json_document/root.md) of a document
that is itself [discarded](../basic_json_document/is_discarded.md) -- in particular, the root of a failed
that is itself [discarded](../basic_json_document/is_discarded.md) — in particular, the root of a failed
[`parse()`](../basic_json_document/parse.md) with `allow_exceptions` set to `#!cpp false`.
A discarded view is also what [`operator[]`](operator[].md) returns for a missing key, an index out of range, or a
@@ -105,10 +105,11 @@ A `basic_json_view` is not convertible to `#!cpp bool`: such a conversion would
## See also
- [operator[]](operator[].md) - access specified element; yields a discarded view where an element is missing
- [(constructor)](basic_json_view.md) - the default constructor creates a discarded view
- [is_discarded (basic_json_document)](../basic_json_document/is_discarded.md) - return whether the last parse failed
- [`operator[]`](operator[].md) - access specified element; yields a discarded view where an element is missing
- [`(constructor)`](basic_json_view.md) - the default constructor creates a discarded view
- [`basic_json_document::is_discarded`](../basic_json_document/is_discarded.md) - return whether the last parse failed
- [`BasicJsonType::is_discarded`](../basic_json/is_discarded.md) - the corresponding function of `basic_json`
- [Zero-copy JSON views](../../features/json_view.md#what-is-different) - how views differ from basic_json
## Version history
File diff suppressed because one or more lines are too long
+5 -4
View File
@@ -4,7 +4,7 @@
bool is_discarded() const noexcept;
```
Returns whether this view is invalid, i.e. does not refer to a value. This is the case for a default-constructed view (see [(constructor)](https://json.nlohmann.me/api/basic_json_view/basic_json_view/index.md)), and for [`root()`](https://json.nlohmann.me/api/basic_json_document/root/index.md) of a document that is itself [discarded](https://json.nlohmann.me/api/basic_json_document/is_discarded/index.md) -- in particular, the root of a failed [`parse()`](https://json.nlohmann.me/api/basic_json_document/parse/index.md) with `allow_exceptions` set to `false`.
Returns whether this view is invalid, i.e. does not refer to a value. This is the case for a default-constructed view (see [(constructor)](https://json.nlohmann.me/api/basic_json_view/basic_json_view/index.md)), and for [`root()`](https://json.nlohmann.me/api/basic_json_document/root/index.md) of a document that is itself [discarded](https://json.nlohmann.me/api/basic_json_document/is_discarded/index.md) — in particular, the root of a failed [`parse()`](https://json.nlohmann.me/api/basic_json_document/parse/index.md) with `allow_exceptions` set to `false`.
A discarded view is also what [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) returns for a missing key, an index out of range, or a JSON pointer that cannot be resolved, and for any access on a view that is itself discarded (so a chain such as `v["a"]["b"]` is safe). [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md) throws instead.
@@ -95,10 +95,11 @@ true
## See also
- [operator[]](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) - access specified element; yields a discarded view where an element is missing
- [(constructor)](https://json.nlohmann.me/api/basic_json_view/basic_json_view/index.md) - the default constructor creates a discarded view
- [is_discarded (basic_json_document)](https://json.nlohmann.me/api/basic_json_document/is_discarded/index.md) - return whether the last parse failed
- [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) - access specified element; yields a discarded view where an element is missing
- [`(constructor)`](https://json.nlohmann.me/api/basic_json_view/basic_json_view/index.md) - the default constructor creates a discarded view
- [`basic_json_document::is_discarded`](https://json.nlohmann.me/api/basic_json_document/is_discarded/index.md) - return whether the last parse failed
- [`BasicJsonType::is_discarded`](https://json.nlohmann.me/api/basic_json/is_discarded/index.md) - the corresponding function of `basic_json`
- [Zero-copy JSON views](https://json.nlohmann.me/features/json_view/#what-is-different) - how views differ from basic_json
## Version history
+1 -1
View File
@@ -92,7 +92,7 @@ Constant.
## See also
- [type](type.md) - return the type of the value
- [`type`](type.md) - return the type of the value
- [`BasicJsonType::is_null`](../basic_json/is_null.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -89,7 +89,7 @@ true
## See also
- [type](https://json.nlohmann.me/api/basic_json_view/type/index.md) - return the type of the value
- [`type`](https://json.nlohmann.me/api/basic_json_view/type/index.md) - return the type of the value
- [`BasicJsonType::is_null`](https://json.nlohmann.me/api/basic_json/is_null/index.md) - the corresponding function of `basic_json`
## Version history
+3 -3
View File
@@ -92,9 +92,9 @@ Constant.
## See also
- [is_number_integer](is_number_integer.md) - return whether the value is an integer or unsigned integer number
- [is_number_unsigned](is_number_unsigned.md) - return whether the value is an unsigned integer number
- [is_number_float](is_number_float.md) - return whether the value is a floating-point number
- [`is_number_integer`](is_number_integer.md) - return whether the value is an integer or unsigned integer number
- [`is_number_unsigned`](is_number_unsigned.md) - return whether the value is an unsigned integer number
- [`is_number_float`](is_number_float.md) - return whether the value is a floating-point number
- [`BasicJsonType::is_number`](../basic_json/is_number.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -89,9 +89,9 @@ true
## See also
- [is_number_integer](https://json.nlohmann.me/api/basic_json_view/is_number_integer/index.md) - return whether the value is an integer or unsigned integer number
- [is_number_unsigned](https://json.nlohmann.me/api/basic_json_view/is_number_unsigned/index.md) - return whether the value is an unsigned integer number
- [is_number_float](https://json.nlohmann.me/api/basic_json_view/is_number_float/index.md) - return whether the value is a floating-point number
- [`is_number_integer`](https://json.nlohmann.me/api/basic_json_view/is_number_integer/index.md) - return whether the value is an integer or unsigned integer number
- [`is_number_unsigned`](https://json.nlohmann.me/api/basic_json_view/is_number_unsigned/index.md) - return whether the value is an unsigned integer number
- [`is_number_float`](https://json.nlohmann.me/api/basic_json_view/is_number_float/index.md) - return whether the value is a floating-point number
- [`BasicJsonType::is_number`](https://json.nlohmann.me/api/basic_json/is_number/index.md) - the corresponding function of `basic_json`
## Version history
+1 -1
View File
@@ -98,7 +98,7 @@ integer-looking token in the source text.
## See also
- [is_number](is_number.md) - return whether the value is a number
- [`is_number`](is_number.md) - return whether the value is a number
- [`BasicJsonType::is_number_float`](../basic_json/is_number_float.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -93,7 +93,7 @@ true
## See also
- [is_number](https://json.nlohmann.me/api/basic_json_view/is_number/index.md) - return whether the value is a number
- [`is_number`](https://json.nlohmann.me/api/basic_json_view/is_number/index.md) - return whether the value is a number
- [`BasicJsonType::is_number_float`](https://json.nlohmann.me/api/basic_json/is_number_float/index.md) - the corresponding function of `basic_json`
## Version history
+2 -2
View File
@@ -97,8 +97,8 @@ values; use [`is_number_unsigned`](is_number_unsigned.md) to test for those spec
## See also
- [is_number](is_number.md) - return whether the value is a number
- [is_number_unsigned](is_number_unsigned.md) - return whether the value is an unsigned integer number
- [`is_number`](is_number.md) - return whether the value is a number
- [`is_number_unsigned`](is_number_unsigned.md) - return whether the value is an unsigned integer number
- [`BasicJsonType::is_number_integer`](../basic_json/is_number_integer.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
@@ -93,8 +93,8 @@ true
## See also
- [is_number](https://json.nlohmann.me/api/basic_json_view/is_number/index.md) - return whether the value is a number
- [is_number_unsigned](https://json.nlohmann.me/api/basic_json_view/is_number_unsigned/index.md) - return whether the value is an unsigned integer number
- [`is_number`](https://json.nlohmann.me/api/basic_json_view/is_number/index.md) - return whether the value is a number
- [`is_number_unsigned`](https://json.nlohmann.me/api/basic_json_view/is_number_unsigned/index.md) - return whether the value is an unsigned integer number
- [`BasicJsonType::is_number_integer`](https://json.nlohmann.me/api/basic_json/is_number_integer/index.md) - the corresponding function of `basic_json`
## Version history
+1 -1
View File
@@ -92,7 +92,7 @@ Constant.
## See also
- [is_number_integer](is_number_integer.md) - return whether the value is an integer or unsigned integer number
- [`is_number_integer`](is_number_integer.md) - return whether the value is an integer or unsigned integer number
- [`BasicJsonType::is_number_unsigned`](../basic_json/is_number_unsigned.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
@@ -89,7 +89,7 @@ true
## See also
- [is_number_integer](https://json.nlohmann.me/api/basic_json_view/is_number_integer/index.md) - return whether the value is an integer or unsigned integer number
- [`is_number_integer`](https://json.nlohmann.me/api/basic_json_view/is_number_integer/index.md) - return whether the value is an integer or unsigned integer number
- [`BasicJsonType::is_number_unsigned`](https://json.nlohmann.me/api/basic_json/is_number_unsigned/index.md) - the corresponding function of `basic_json`
## Version history
+3 -3
View File
@@ -92,9 +92,9 @@ Constant.
## See also
- [is_structured](is_structured.md) - return whether the type is structured
- [size](size.md) - the number of elements
- [empty](empty.md) - whether there are no elements
- [`is_structured`](is_structured.md) - return whether the type is structured
- [`size`](size.md) - the number of elements
- [`empty`](empty.md) - whether there are no elements
- [`BasicJsonType::is_object`](../basic_json/is_object.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -89,9 +89,9 @@ true
## See also
- [is_structured](https://json.nlohmann.me/api/basic_json_view/is_structured/index.md) - return whether the type is structured
- [size](https://json.nlohmann.me/api/basic_json_view/size/index.md) - the number of elements
- [empty](https://json.nlohmann.me/api/basic_json_view/empty/index.md) - whether there are no elements
- [`is_structured`](https://json.nlohmann.me/api/basic_json_view/is_structured/index.md) - return whether the type is structured
- [`size`](https://json.nlohmann.me/api/basic_json_view/size/index.md) - the number of elements
- [`empty`](https://json.nlohmann.me/api/basic_json_view/empty/index.md) - whether there are no elements
- [`BasicJsonType::is_object`](https://json.nlohmann.me/api/basic_json/is_object/index.md) - the corresponding function of `basic_json`
## Version history
+1 -1
View File
@@ -92,7 +92,7 @@ Constant.
## See also
- [is_structured](is_structured.md) - return whether the type is structured (the complement of this function, for a
- [`is_structured`](is_structured.md) - return whether the type is structured (the complement of this function, for a
non-discarded view)
- [`BasicJsonType::is_primitive`](../basic_json/is_primitive.md) - the corresponding function of `basic_json`
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -89,7 +89,7 @@ true
## See also
- [is_structured](https://json.nlohmann.me/api/basic_json_view/is_structured/index.md) - return whether the type is structured (the complement of this function, for a non-discarded view)
- [`is_structured`](https://json.nlohmann.me/api/basic_json_view/is_structured/index.md) - return whether the type is structured (the complement of this function, for a non-discarded view)
- [`BasicJsonType::is_primitive`](https://json.nlohmann.me/api/basic_json/is_primitive/index.md) - the corresponding function of `basic_json`
## Version history
+1 -1
View File
@@ -92,7 +92,7 @@ Constant.
## See also
- [source_offset](source_offset.md) - byte offset of this value in the source text, which differs for strings: an
- [`source_offset`](source_offset.md) - byte offset of this value in the source text, which differs for strings: an
escaped string has none
- [`BasicJsonType::is_string`](../basic_json/is_string.md) - the corresponding function of `basic_json`
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -89,7 +89,7 @@ true
## See also
- [source_offset](https://json.nlohmann.me/api/basic_json_view/source_offset/index.md) - byte offset of this value in the source text, which differs for strings: an escaped string has none
- [`source_offset`](https://json.nlohmann.me/api/basic_json_view/source_offset/index.md) - byte offset of this value in the source text, which differs for strings: an escaped string has none
- [`BasicJsonType::is_string`](https://json.nlohmann.me/api/basic_json/is_string/index.md) - the corresponding function of `basic_json`
## Version history
+2 -2
View File
@@ -92,8 +92,8 @@ Constant.
## See also
- [is_primitive](is_primitive.md) - return whether the type is primitive
- [size](size.md), [empty](empty.md) - the number of elements, and whether there are none
- [`is_primitive`](is_primitive.md) - return whether the type is primitive
- [`size`](size.md), [`empty`](empty.md) - the number of elements, and whether there are none
- [`BasicJsonType::is_structured`](../basic_json/is_structured.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -89,8 +89,8 @@ true
## See also
- [is_primitive](https://json.nlohmann.me/api/basic_json_view/is_primitive/index.md) - return whether the type is primitive
- [size](https://json.nlohmann.me/api/basic_json_view/size/index.md), [empty](https://json.nlohmann.me/api/basic_json_view/empty/index.md) - the number of elements, and whether there are none
- [`is_primitive`](https://json.nlohmann.me/api/basic_json_view/is_primitive/index.md) - return whether the type is primitive
- [`size`](https://json.nlohmann.me/api/basic_json_view/size/index.md), [`empty`](https://json.nlohmann.me/api/basic_json_view/empty/index.md) - the number of elements, and whether there are none
- [`BasicJsonType::is_structured`](https://json.nlohmann.me/api/basic_json/is_structured/index.md) - the corresponding function of `basic_json`
## Version history
+5 -5
View File
@@ -4,7 +4,7 @@
/* unspecified */ items() const noexcept;
```
Returns a range of items -- (key, value) pairs -- for use in range-based for loops. An item's `#!cpp key()` is a
Returns a range of items — (key, value) pairs — for use in range-based for loops. An item's `#!cpp key()` is a
`#!cpp string_view_t` (for an array element, its index converted to a string, as for
[`BasicJsonType::items()`](../basic_json/items.md)), and its `#!cpp value()` is a `basic_json_view` of the element.
@@ -47,7 +47,7 @@ Constant.
## Notes
As for [`begin()`](begin.md)/[`end()`](end.md), `items()` visits **every** member of an object, including all
occurrences of a duplicate key -- unlike [`operator[]`](operator[].md), [`at`](at.md), [`find`](find.md),
occurrences of a duplicate key — unlike [`operator[]`](operator[].md), [`at`](at.md), [`find`](find.md),
and [`contains`](contains.md), which resolve to the *first* member with a given key. See the
[Notes on duplicate keys](operator[].md#notes) of `operator[]`.
@@ -63,8 +63,8 @@ and [`contains`](contains.md), which resolve to the *first* member with a given
The example below shows a settings object whose source text records every update to a key as a duplicate
member, in the order they happened. `items()` walks all of them, so the update history is visible, while
[`operator[]`](operator[].md) only ever sees the *first* one and [`materialize()`](materialize.md) -- like
[`BasicJsonType::parse()`](../basic_json/parse.md) -- keeps only the *last*.
[`operator[]`](operator[].md) only ever sees the *first* one and [`materialize()`](materialize.md) — like
[`BasicJsonType::parse()`](../basic_json/parse.md) — keeps only the *last*.
```cpp
#include <iostream>
@@ -105,7 +105,7 @@ and [`contains`](contains.md), which resolve to the *first* member with a given
## See also
- [begin](begin.md), [end](end.md) - the iterators `items()` is built on
- [`begin`](begin.md), [`end`](end.md) - the iterators `items()` is built on
- [`BasicJsonType::items`](../basic_json/items.md) - the corresponding function of `basic_json`
## Version history
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -4,7 +4,7 @@
/* unspecified */ items() const noexcept;
```
Returns a range of items -- (key, value) pairs -- for use in range-based for loops. An item's `key()` is a `string_view_t` (for an array element, its index converted to a string, as for [`BasicJsonType::items()`](https://json.nlohmann.me/api/basic_json/items/index.md)), and its `value()` is a `basic_json_view` of the element.
Returns a range of items — (key, value) pairs — for use in range-based for loops. An item's `key()` is a `string_view_t` (for an array element, its index converted to a string, as for [`BasicJsonType::items()`](https://json.nlohmann.me/api/basic_json/items/index.md)), and its `value()` is a `basic_json_view` of the element.
The returned type is not part of the public API and may change between versions; use a range-based for loop (see the example), or `decltype(v.items())` if you need to name it.
@@ -40,7 +40,7 @@ Constant.
## Notes
As for [`begin()`](https://json.nlohmann.me/api/basic_json_view/begin/index.md)/[`end()`](https://json.nlohmann.me/api/basic_json_view/end/index.md), `items()` visits **every** member of an object, including all occurrences of a duplicate key -- unlike [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md), [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md), and [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md), which resolve to the *first* member with a given key. See the [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes) of `operator[]`.
As for [`begin()`](https://json.nlohmann.me/api/basic_json_view/begin/index.md)/[`end()`](https://json.nlohmann.me/api/basic_json_view/end/index.md), `items()` visits **every** member of an object, including all occurrences of a duplicate key — unlike [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md), [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md), and [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md), which resolve to the *first* member with a given key. See the [Notes on duplicate keys](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/#notes) of `operator[]`.
Lifetime issues
@@ -50,7 +50,7 @@ Unlike `BasicJsonType::items()` (see [#2040](https://github.com/nlohmann/json/is
Example
The example below shows a settings object whose source text records every update to a key as a duplicate member, in the order they happened. `items()` walks all of them, so the update history is visible, while [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) only ever sees the *first* one and [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) -- like [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) -- keeps only the *last*.
The example below shows a settings object whose source text records every update to a key as a duplicate member, in the order they happened. `items()` walks all of them, so the update history is visible, while [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) only ever sees the *first* one and [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) — like [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) — keeps only the *last*.
```
#include <iostream>
@@ -89,7 +89,7 @@ last "retries" kept by materialize(): 5
## See also
- [begin](https://json.nlohmann.me/api/basic_json_view/begin/index.md), [end](https://json.nlohmann.me/api/basic_json_view/end/index.md) - the iterators `items()` is built on
- [`begin`](https://json.nlohmann.me/api/basic_json_view/begin/index.md), [`end`](https://json.nlohmann.me/api/basic_json_view/end/index.md) - the iterators `items()` is built on
- [`BasicJsonType::items`](https://json.nlohmann.me/api/basic_json/items/index.md) - the corresponding function of `basic_json`
## Version history
+4 -3
View File
@@ -28,7 +28,7 @@ Linear in the size of the subtree.
## Notes
`materialize()` replays the subtree through the same SAX builder [`BasicJsonType::parse()`](../basic_json/parse.md)
uses, so the result matches it exactly -- including, for an object, that a repeated key keeps only its
uses, so the result matches it exactly — including, for an object, that a repeated key keeps only its
last value. The replay is iterative, so it is not limited by the call stack the way a naive recursive conversion
would be; the JSON nesting depth is limited only by available memory, as for `BasicJsonType::parse()` itself.
@@ -43,7 +43,7 @@ never caches the result.
??? example
The example below skips messages that are not useful -- a discarded value, or an empty array -- using only
The example below skips messages that are not useful — a discarded value, or an empty array — using only
[`is_array()`](is_array.md) and [`empty()`](empty.md), and calls `materialize()` only for the messages that are
actually used, so no `BasicJsonType` value (and none of its per-element allocations) is ever built for the
skipped ones.
@@ -96,10 +96,11 @@ never caches the result.
## See also
- [root](../basic_json_document/root.md) - the view of a document's root value
- [`root`](../basic_json_document/root.md) - the view of a document's root value
- [`BasicJsonType::parse`](../basic_json/parse.md) - build a `BasicJsonType` value directly from a JSON text
- [`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) - source positions on parsed values (not
produced by `materialize()`)
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - when to build a basic_json value from a view
## Version history
File diff suppressed because one or more lines are too long
+4 -3
View File
@@ -24,7 +24,7 @@ Linear in the size of the subtree.
## Notes
`materialize()` replays the subtree through the same SAX builder [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) uses, so the result matches it exactly -- including, for an object, that a repeated key keeps only its last value. The replay is iterative, so it is not limited by the call stack the way a naive recursive conversion would be; the JSON nesting depth is limited only by available memory, as for `BasicJsonType::parse()` itself.
`materialize()` replays the subtree through the same SAX builder [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) uses, so the result matches it exactly — including, for an object, that a repeated key keeps only its last value. The replay is iterative, so it is not limited by the call stack the way a naive recursive conversion would be; the JSON nesting depth is limited only by available memory, as for `BasicJsonType::parse()` itself.
Unlike parsing with [`JSON_DIAGNOSTIC_POSITIONS`](https://json.nlohmann.me/api/macros/json_diagnostic_positions/index.md) enabled, the values produced by `materialize()` do not carry source positions. The index has the start offset of every value, but not the end of arrays, objects, and escaped strings, which the positions also need.
@@ -34,7 +34,7 @@ Calling `materialize()` on the same view repeatedly builds a new, independent `B
Example
The example below skips messages that are not useful -- a discarded value, or an empty array -- using only [`is_array()`](https://json.nlohmann.me/api/basic_json_view/is_array/index.md) and [`empty()`](https://json.nlohmann.me/api/basic_json_view/empty/index.md), and calls `materialize()` only for the messages that are actually used, so no `BasicJsonType` value (and none of its per-element allocations) is ever built for the skipped ones.
The example below skips messages that are not useful — a discarded value, or an empty array — using only [`is_array()`](https://json.nlohmann.me/api/basic_json_view/is_array/index.md) and [`empty()`](https://json.nlohmann.me/api/basic_json_view/empty/index.md), and calls `materialize()` only for the messages that are actually used, so no `BasicJsonType` value (and none of its per-element allocations) is ever built for the skipped ones.
```
#include <array>
@@ -82,9 +82,10 @@ skipped
## See also
- [root](https://json.nlohmann.me/api/basic_json_document/root/index.md) - the view of a document's root value
- [`root`](https://json.nlohmann.me/api/basic_json_document/root/index.md) - the view of a document's root value
- [`BasicJsonType::parse`](https://json.nlohmann.me/api/basic_json/parse/index.md) - build a `BasicJsonType` value directly from a JSON text
- [`JSON_DIAGNOSTIC_POSITIONS`](https://json.nlohmann.me/api/macros/json_diagnostic_positions/index.md) - source positions on parsed values (not produced by `materialize()`)
- [Zero-copy JSON views](https://json.nlohmann.me/features/json_view/#getting-values-out-without-copying) - when to build a basic_json value from a view
## Version history
+6 -5
View File
@@ -10,14 +10,14 @@ enum class number_format {
This enumeration is used in [`dump`](dump.md) to choose how numbers are written. Two values are differentiated:
shortest
: integers are copied from the source text -- already canonical in JSON -- except that `#!cpp -0` becomes
: integers are copied from the source text — already canonical in JSON — except that `#!cpp -0` becomes
`#!cpp 0`, the way [`BasicJsonType::parse()`](../basic_json/parse.md) reads it; floats are written with the
library's shortest round-trip conversion, exactly as [`BasicJsonType::dump()`](../basic_json/dump.md) would (e.g.
`#!cpp 1.5`, `#!cpp 100.0`, `#!cpp 1e+100`)
source
: every number is copied exactly as it appears in the source text -- `#!cpp 1.50`, `#!cpp 1E2`, `#!cpp -0`, all
digits of an integer literal with more digits than any number type holds -- something `BasicJsonType` cannot do,
: every number is copied exactly as it appears in the source text — `#!cpp 1.50`, `#!cpp 1E2`, `#!cpp -0`, all
digits of an integer literal with more digits than any number type holds — something `BasicJsonType` cannot do,
since parsing already reduces every number to its parsed value
## Examples
@@ -71,10 +71,11 @@ source
## See also
- [dump](dump.md) - serialize to a JSON-formatted string
- [number_token](number_token.md) - get a single number's token text without dumping the whole value
- [`dump`](dump.md) - serialize to a JSON-formatted string
- [`number_token`](number_token.md) - get a single number's token text without dumping the whole value
- [`BasicJsonType::error_handler_t`](../basic_json/error_handler_t.md) - the analogous enumeration for
`BasicJsonType::dump`'s decoding-error behavior
- [Zero-copy JSON views](../../features/json_view.md#writing-a-view-back) - writing numbers as they appeared in the source
## Version history
File diff suppressed because one or more lines are too long
+5 -4
View File
@@ -9,9 +9,9 @@ enum class number_format {
This enumeration is used in [`dump`](https://json.nlohmann.me/api/basic_json_view/dump/index.md) to choose how numbers are written. Two values are differentiated:
shortest : integers are copied from the source text -- already canonical in JSON -- except that `-0` becomes `0`, the way [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) reads it; floats are written with the library's shortest round-trip conversion, exactly as [`BasicJsonType::dump()`](https://json.nlohmann.me/api/basic_json/dump/index.md) would (e.g. `1.5`, `100.0`, `1e+100`)
shortest : integers are copied from the source text — already canonical in JSON — except that `-0` becomes `0`, the way [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) reads it; floats are written with the library's shortest round-trip conversion, exactly as [`BasicJsonType::dump()`](https://json.nlohmann.me/api/basic_json/dump/index.md) would (e.g. `1.5`, `100.0`, `1e+100`)
source : every number is copied exactly as it appears in the source text -- `1.50`, `1E2`, `-0`, all digits of an integer literal with more digits than any number type holds -- something `BasicJsonType` cannot do, since parsing already reduces every number to its parsed value
source : every number is copied exactly as it appears in the source text — `1.50`, `1E2`, `-0`, all digits of an integer literal with more digits than any number type holds — something `BasicJsonType` cannot do, since parsing already reduces every number to its parsed value
## Examples
@@ -59,9 +59,10 @@ Output:
## See also
- [dump](https://json.nlohmann.me/api/basic_json_view/dump/index.md) - serialize to a JSON-formatted string
- [number_token](https://json.nlohmann.me/api/basic_json_view/number_token/index.md) - get a single number's token text without dumping the whole value
- [`dump`](https://json.nlohmann.me/api/basic_json_view/dump/index.md) - serialize to a JSON-formatted string
- [`number_token`](https://json.nlohmann.me/api/basic_json_view/number_token/index.md) - get a single number's token text without dumping the whole value
- [`BasicJsonType::error_handler_t`](https://json.nlohmann.me/api/basic_json/error_handler_t/index.md) - the analogous enumeration for `BasicJsonType::dump`'s decoding-error behavior
- [Zero-copy JSON views](https://json.nlohmann.me/features/json_view/#writing-a-view-back) - writing numbers as they appeared in the source
## Version history
+8 -7
View File
@@ -9,7 +9,7 @@ Returns the number exactly as it appears in the source text, without parsing or
## Return value
The number's token text, as a [`string_view_t`](index.md#member-types) into the document's
[`source()`](../basic_json_document/source.md) text -- for example `#!cpp "1.50"`, `#!cpp "1E2"`, `#!cpp "-0"`, or an
[`source()`](../basic_json_document/source.md) text — for example `#!cpp "1.50"`, `#!cpp "1E2"`, `#!cpp "-0"`, or an
integer literal with more digits than any number type holds (such as a 30-digit integer, which [`get<T>()`](get.md)
and [`materialize()`](materialize.md) can only represent approximately, as a `number_float_t`).
@@ -35,12 +35,12 @@ Constant.
`BasicJsonType` has no counterpart to this function: once a number is parsed into `number_integer_t`,
`number_unsigned_t`, or `number_float_t`, its original textual form (leading zeros aside, which are already rejected
by the grammar; trailing zeros in the fraction; the case and sign of the exponent; ...) is gone. `number_token()` is
useful precisely where that form must survive -- a price or an identifier that must be reproduced exactly, or a
useful precisely where that form must survive — a price or an identifier that must be reproduced exactly, or a
number too large for any of `BasicJsonType`'s number types to hold without loss.
The returned [`string_view_t`](index.md#member-types) always points into the document's
[`source()`](../basic_json_document/source.md) text -- numbers are never decoded into the document's separate string
buffer -- and is valid exactly as long as that text is, see the [validity rules](index.md) of `basic_json_view`.
[`source()`](../basic_json_document/source.md) text — numbers are never decoded into the document's separate string
buffer — and is valid exactly as long as that text is, see the [validity rules](index.md) of `basic_json_view`.
## Examples
@@ -48,7 +48,7 @@ buffer -- and is valid exactly as long as that text is, see the [validity rules]
The example below keeps a price and an order ID exactly as they were written in an incoming order, where
converting them with [`get<T>()`](get.md) would lose information: the price picks up floating-point rounding, and
the order ID -- more digits than a 64-bit integer holds -- can only be approximated as a `#!cpp double` once
the order ID — more digits than a 64-bit integer holds — can only be approximated as a `#!cpp double` once
`#!cpp materialize()`d.
```cpp
@@ -97,11 +97,12 @@ buffer -- and is valid exactly as long as that text is, see the [validity rules]
## See also
- [get](get.md) - convert the value to a given type
- [get_string](get_string.md) - the string, without a copy
- [`get`](get.md) - convert the value to a given type
- [`get_string`](get_string.md) - the string, without a copy
- [`BasicJsonType::number_integer_t`](../basic_json/number_integer_t.md),
[`number_unsigned_t`](../basic_json/number_unsigned_t.md), [`number_float_t`](../basic_json/number_float_t.md) - the
number types `#!cpp get<T>()` and `materialize()` convert into
- [Zero-copy JSON views](../../features/json_view.md#getting-values-out-without-copying) - reading a number exactly as written
## Version history
File diff suppressed because one or more lines are too long

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