mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 14:05:18 +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>
20 lines
641 B
C++
20 lines
641 B
C++
#include <iostream>
|
|
#include <nlohmann/json_view.hpp>
|
|
|
|
using json_document = nlohmann::json_document;
|
|
|
|
int main()
|
|
{
|
|
std::cout << std::boolalpha;
|
|
|
|
// with allow_exceptions == false, a parse error produces a discarded
|
|
// document instead of throwing -- exactly like basic_json::parse()
|
|
json_document doc = json_document::parse(R"({"a": )", /* allow_exceptions */ false);
|
|
std::cout << doc.is_discarded() << '\n';
|
|
std::cout << doc.root().is_discarded() << '\n';
|
|
|
|
// a successful parse is never discarded
|
|
json_document ok = json_document::parse(R"({"a": 1})", false);
|
|
std::cout << ok.is_discarded() << '\n';
|
|
}
|