mirror of
https://github.com/nlohmann/json.git
synced 2026-03-06 09:16:25 +00:00
Reorganize directories (#3462)
* 🚚 move files * 🚚 rename doc folder to docs * 🚚 rename test folder to tests
This commit is contained in:
50
docs/mkdocs/docs/api/basic_json/flatten.md
Normal file
50
docs/mkdocs/docs/api/basic_json/flatten.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# <small>nlohmann::basic_json::</small>flatten
|
||||
|
||||
```cpp
|
||||
basic_json flatten() const;
|
||||
```
|
||||
|
||||
The function creates a JSON object whose keys are JSON pointers (see [RFC 6901](https://tools.ietf.org/html/rfc6901))
|
||||
and whose values are all primitive (see [`is_primitive()`](is_primitive.md) for more information). The original JSON
|
||||
value can be restored using the [`unflatten()`](unflatten.md) function.
|
||||
|
||||
## Return value
|
||||
|
||||
an object that maps JSON pointers to primitive values
|
||||
|
||||
## Exception safety
|
||||
|
||||
Strong exception safety: if an exception occurs, the original value stays intact.
|
||||
|
||||
## Complexity
|
||||
|
||||
Linear in the size the JSON value.
|
||||
|
||||
## Notes
|
||||
|
||||
Empty objects and arrays are flattened to `#!json null` and will not be reconstructed correctly by the
|
||||
[`unflatten()`](unflatten.md) function.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
The following code shows how a JSON object is flattened to an object whose keys consist of JSON pointers.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/flatten.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/flatten.output"
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [unflatten](unflatten.md) the reverse function
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 2.0.0.
|
||||
Reference in New Issue
Block a user