json/doc/mkdocs/docs/api/basic_json/operator_gtgt.md

60 lines
1.3 KiB
Markdown
Raw Normal View History

2021-11-03 16:51:19 +03:00
# operator>>(basic_json)
```cpp
2021-11-05 16:48:28 +03:00
std::istream& operator>>(std::istream& i, basic_json& j);
2021-11-03 16:51:19 +03:00
```
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.
2021-11-05 16:26:19 +03:00
## Notes
2021-11-03 16:51:19 +03:00
A UTF-8 byte order mark is silently ignored.
2021-11-05 16:26:19 +03:00
## Examples
2021-11-03 16:51:19 +03:00
??? 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
2021-11-07 15:13:37 +03:00
- [accept](accept.md) - check if the input is valid JSON
- [parse](parse.md) - deserialize from a compatible input
2021-11-03 16:51:19 +03:00
## Version history
- Added in version 1.0.0