mirror of
https://github.com/nlohmann/json.git
synced 2026-02-23 03:46:26 +00:00
Add operator<<(json_pointer) (#3601)
* Add operator<< for json_pointer * Deprecate json_pointer::operator string_t() * Update documentation * Move operator<<(basic_json) example * Add example * Add mkdocs-redirects * Move operator<< and operator>> doc pages out of basic_json/ * Rename JSON pointer operator_string to operator_string_t * Add unit test
This commit is contained in:
committed by
GitHub
parent
7777300442
commit
e3095f636f
@@ -96,7 +96,7 @@ Linear in the length of the input. The parser is a predictive LL(1) parser.
|
||||
## See also
|
||||
|
||||
- [parse](parse.md) - deserialize from a compatible input
|
||||
- [operator>>](operator_gtgt.md) - deserialize from stream
|
||||
- [operator>>](../operator_gtgt.md) - deserialize from stream
|
||||
|
||||
## Version history
|
||||
|
||||
|
||||
@@ -283,8 +283,8 @@ Access to the JSON value
|
||||
|
||||
## Non-member functions
|
||||
|
||||
- [**operator<<(std::ostream&)**](operator_ltlt.md) - serialize to stream
|
||||
- [**operator>>(std::istream&)**](operator_gtgt.md) - deserialize from stream
|
||||
- [**operator<<(std::ostream&)**](../operator_ltlt.md) - serialize to stream
|
||||
- [**operator>>(std::istream&)**](../operator_gtgt.md) - deserialize from stream
|
||||
- [**to_string**](to_string.md) - user-defined `to_string` function for JSON values
|
||||
|
||||
## Literals
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
# operator>>(basic_json)
|
||||
|
||||
```cpp
|
||||
std::istream& operator>>(std::istream& i, basic_json& j);
|
||||
```
|
||||
|
||||
Deserializes an input stream to a JSON value.
|
||||
|
||||
## Parameters
|
||||
|
||||
`i` (in, out)
|
||||
: input stream to read a serialized JSON value from
|
||||
|
||||
`j` (in, out)
|
||||
: JSON value to write the deserialized input to
|
||||
|
||||
## Return value
|
||||
|
||||
the stream `i`
|
||||
|
||||
## Exceptions
|
||||
|
||||
- Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an unexpected token.
|
||||
- Throws [`parse_error.102`](../../home/exceptions.md#jsonexceptionparse_error102) if to_unicode fails or surrogate
|
||||
error.
|
||||
- Throws [`parse_error.103`](../../home/exceptions.md#jsonexceptionparse_error103) if to_unicode fails.
|
||||
|
||||
## Complexity
|
||||
|
||||
Linear in the length of the input. The parser is a predictive LL(1) parser.
|
||||
|
||||
## Notes
|
||||
|
||||
A UTF-8 byte order mark is silently ignored.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
The example below shows how a JSON value is constructed by reading a serialization from a stream.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/operator_deserialize.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/operator_deserialize.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [accept](accept.md) - check if the input is valid JSON
|
||||
- [parse](parse.md) - deserialize from a compatible input
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
This function replaces function `#!cpp std::istream& operator<<(basic_json& j, std::istream& i)` which has
|
||||
been deprecated in version 3.0.0. It will be removed in version 4.0.0. Please replace calls like `#!cpp j << i;`
|
||||
with `#!cpp i >> j;`.
|
||||
@@ -1,62 +0,0 @@
|
||||
# operator<<(basic_json)
|
||||
|
||||
```cpp
|
||||
std::ostream& operator<<(std::ostream& o, const basic_json& j);
|
||||
```
|
||||
|
||||
Serialize the given JSON value `j` to the output stream `o`. The JSON value will be serialized using the
|
||||
[`dump`](dump.md) member function.
|
||||
|
||||
- The indentation of the output can be controlled with the member variable `width` of the output stream `o`. For
|
||||
instance, using the manipulator `std::setw(4)` on `o` sets the indentation level to `4` and the serialization result
|
||||
is the same as calling `dump(4)`.
|
||||
- The indentation character can be controlled with the member variable `fill` of the output stream `o`. For instance,
|
||||
the manipulator `std::setfill('\\t')` sets indentation to use a tab character rather than the default space character.
|
||||
|
||||
## Parameters
|
||||
|
||||
`o` (in, out)
|
||||
: stream to serialize to
|
||||
|
||||
`j` (in)
|
||||
: JSON value to serialize
|
||||
|
||||
## Return value
|
||||
|
||||
the stream `o`
|
||||
|
||||
## Exceptions
|
||||
|
||||
Throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) if a string stored inside the JSON value
|
||||
is not UTF-8 encoded. Note that unlike the [`dump`](dump.md) member functions, no `error_handler` can be set.
|
||||
|
||||
## Complexity
|
||||
|
||||
Linear.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
The example below shows the serialization with different parameters to `width` to adjust the indentation level.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/operator_serialize.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/operator_serialize.output"
|
||||
```
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 1.0.0
|
||||
- Support for indentation character added in version 3.0.0.
|
||||
|
||||
!!! warning "Deprecation"
|
||||
|
||||
This function replaces function `#!cpp std::ostream& operator>>(const basic_json& j, std::ostream& o)` which has
|
||||
been deprecated in version 3.0.0. It will be removed in version 4.0.0. Please replace calls like `#!cpp j >> o;`
|
||||
with `#!cpp o << j;`.
|
||||
@@ -196,7 +196,7 @@ super-linear complexity.
|
||||
## See also
|
||||
|
||||
- [accept](accept.md) - check if the input is valid JSON
|
||||
- [operator>>](operator_gtgt.md) - deserialize from stream
|
||||
- [operator>>](../operator_gtgt.md) - deserialize from stream
|
||||
|
||||
## Version history
|
||||
|
||||
|
||||
Reference in New Issue
Block a user