mirror of
https://github.com/nlohmann/json.git
synced 2026-10-13 09:47:12 +00:00
basic_json_document gets a second template parameter, Editable (false by default), plus the aliases json_editable_document, json_editable_view, ordered_json_editable_document and ordered_json_editable_view. Editable documents can change values and structure without rewriting the source text: set()/push_back() on values, keys, array indices and JSON pointers; insert() before an array element; erase() of an object key, array index or JSON pointer. New values and element sequences go into edit storage that the document owns and never moves, so views keep referring to their value across edits and a parsed node never moves. Read-only documents walk the plain node array and are unaffected. Strings are checked for UTF-8 on entry, so dump() of an editable document never throws type_error.316. Binary values cannot be stored (type_error.319). A seeded differential test applies random edits to an editable document and to the equivalent ordered_json and compares both after every step. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
1.4 KiB
1.4 KiB
nlohmann::json_editable_view
Defined in header <nlohmann/json_view.hpp>
using json_editable_view = basic_json_view<json, true>;
This type is a basic_json_view of a value of a
json_editable_document. It offers the same read-only interface as
json_view; what is different is what it can be a view of -- a value that
set and push_back can change, with every view
still referring to it seeing the change, see Edits.
Examples
??? example
The example below is the same as [`json_editable_document`'s](json_editable_document.md): every view read back
out of the document -- `#!cpp doc.root()` and the views nested under it -- sees the edits made through `set`.
```cpp
--8<-- "examples/json_editable_document.cpp"
```
Output:
```json
--8<-- "examples/json_editable_document.output"
```
See also
- json_editable_document - the document type this view refers into
- json_view - the corresponding read-only view
- ordered_json_editable_view - the corresponding view for
ordered_json_editable_document
Version history
Since version 3.13.0.