WhisperCom/doc/mkdocs/docs/api/basic_json/flatten.md
Dominik Meyer cc002ebfbb Squashed 'libs/json/' content from commit f42a74b8
git-subtree-dir: libs/json
git-subtree-split: f42a74b8f53cc308647123d49d33d1c8122e3f42
2021-08-22 01:28:31 +02:00

1.0 KiB

basic_json::flatten

basic_json flatten() const;

The function creates a JSON object whose keys are JSON pointers (see RFC 6901) and whose values are all primitive (see is_primitive() for more information). The original JSON value can be restored using the unflatten() 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() function.

Example

??? 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"
```

Version history

  • Added in version 2.0.0.