mirror of
https://github.com/nlohmann/json.git
synced 2026-10-11 17:03:42 +07:00
- API pages for set and push_back of basic_json_document and for the editable aliases; the class overviews name the Editable parameter - type_error.319 on the exceptions page - the feature page explains editing, and the examples show when it helps: a configuration file changed without reformatting it Signed-off-by: Niels Lohmann <mail@nlohmann.me>
16 lines
638 B
C++
16 lines
638 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, 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';
|
|
}
|