mirror of
https://github.com/nlohmann/json.git
synced 2026-10-04 05:30:31 +00:00
- API pages for basic_json_document and basic_json_view, one per member, and for the four aliases, each with an example - features/json_view.md: the problem the view solves, ownership and lifetime, what matches basic_json::parse() and what differs, and when to choose json, ordered_json, SAX, or the view - the examples show why one would use the view, not only how: borrowed vs. owned input, reading a few fields and materializing one subtree, reusing a document across many messages - registered in the mkdocs navigation, llms.txt, the docset, the exceptions page (out_of_range.416), architecture.md, the integration page, and the README; the yyjson credit is added to the README and license.md Signed-off-by: Niels Lohmann <mail@nlohmann.me>
14 lines
493 B
C++
14 lines
493 B
C++
#include <iostream>
|
|
#include <nlohmann/json_view.hpp>
|
|
|
|
using ordered_json_document = nlohmann::ordered_json_document;
|
|
|
|
int main()
|
|
{
|
|
// ordered_json_document is basic_json_document<nlohmann::ordered_json>:
|
|
// materialize() preserves the insertion (source) order of object keys,
|
|
// instead of sorting them like json_document does
|
|
ordered_json_document doc = ordered_json_document::parse(R"({"z": 1, "a": 2, "m": 3})");
|
|
std::cout << doc.root().materialize().dump() << '\n';
|
|
}
|