basic_json_document and basic_json_view take a view_mode (read_only, the default, or editable) instead of a bool: basic_json_document<json, true> did not say what true means. The shortcut aliases are unchanged. The kind of a node is a node_kind (the value_t values plus link, 10 as before), which removes the static_cast<std::uint8_t>(value_t::...) of every comparison. The node and image layouts are unchanged. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
16 lines
663 B
C++
16 lines
663 B
C++
#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, nlohmann::view_mode::editable>
|
|
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';
|
|
}
|