mirror of
https://github.com/nlohmann/json.git
synced 2026-10-02 23:15:17 +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
733 B
C++
20 lines
733 B
C++
#include <iostream>
|
|
#include <nlohmann/json.hpp>
|
|
#include <nlohmann/json_view.hpp>
|
|
|
|
using json_document = nlohmann::json_document;
|
|
|
|
int main()
|
|
{
|
|
std::cout << std::boolalpha;
|
|
|
|
// accept() behaves exactly like basic_json::accept(): the same inputs are
|
|
// accepted or rejected, with the same ignore_comments/ignore_trailing_commas
|
|
// options
|
|
std::cout << json_document::accept(R"({"a": 1})") << '\n';
|
|
std::cout << json_document::accept(R"({"a": 1,})") << '\n'; // trailing comma: rejected by default
|
|
std::cout << json_document::accept(R"({"a": 1,})", false, true) << '\n'; // ignore_trailing_commas
|
|
|
|
std::cout << (json_document::accept(R"({"a": 1})") == nlohmann::json::accept(R"({"a": 1})")) << '\n';
|
|
}
|