nlohmann::ordered_json_editable_view¶
Defined in header <nlohmann/json_view.hpp>
using ordered_json_editable_view = basic_json_view<ordered_json, true>;
This type is a basic_json_view of a value of an ordered_json_editable_document, the corresponding view for ordered_json_view the way json_editable_view is for json_view.
Examples¶
Example
The example below is the same as ordered_json_editable_document's: the views set returns see the document's member order preserved on materialize(), unlike for a json_editable_document.
#include <iostream>
#include <nlohmann/json_view.hpp>
using ordered_json_editable_document = nlohmann::ordered_json_editable_document;
int main()
{
// ordered_json_editable_document is basic_json_document<nlohmann::ordered_json, true>
ordered_json_editable_document doc = ordered_json_editable_document::parse(R"({"z": 1, "a": 2, "m": 3})");
doc.set(doc.root(), "b", 4); // set() always appends a new member at the end
// materialize() preserves the document order (with "b" at the end),
// instead of sorting the keys the way json_editable_document does
std::cout << doc.root().materialize().dump() << '\n';
}
Output:
{"z":1,"a":2,"m":3,"b":4}
See also¶
- ordered_json_editable_document - the document type this view refers into
- ordered_json_view - the corresponding read-only view
- json_editable_view - the corresponding view for
json_editable_document
Version history¶
Since version 3.13.0 unreleased.