mirror of
https://github.com/nlohmann/json.git
synced 2025-05-11 05:33:55 +00:00
* 🔥 consolidate documentation * ♻️ overwork std specializations * 🚚 move images files to mkdocs * ♻️ fix URLs * 🔧 tweak MkDocs configuration * 🔧 add namespaces * 📝 document deprecations * 📝 document documentation generation * 🚸 improve search * 🚸 add examples * 🚧 start adding documentation for macros * 📝 add note for https://github.com/nlohmann/json/issues/874#issuecomment-1001699139 * 📝 overwork example handling * 📝 fix Markdown tables
1.1 KiB
1.1 KiB
nlohmann::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.
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 the reverse function
Version history
- Added in version 2.0.0.