mirror of
https://github.com/nlohmann/json.git
synced 2026-10-22 22:08:55 +00:00
deploy: 4155e2938f
This commit is contained in:
1 parent
be4d0a6f4b
commit
90f0c9d411
714 files changed
+22067
-622
No files matched your search
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json_view.hpp>
|
||||
|
||||
using json_document = nlohmann::json_document;
|
||||
|
||||
int main()
|
||||
{
|
||||
// the build log of a running job; front() reads just the earliest event
|
||||
// without materializing the (possibly long) rest of the log
|
||||
json_document log = json_document::parse(R"(["queued", "started", "compiling", "linking", "done"])");
|
||||
std::cout << log.root().front().materialize().dump() << '\n';
|
||||
|
||||
// an empty log -- front() throws instead of the undefined behavior
|
||||
// basic_json::front() has for an empty array
|
||||
json_document empty_log = json_document::parse("[]");
|
||||
try
|
||||
{
|
||||
static_cast<void>(empty_log.root().front());
|
||||
}
|
||||
catch (const nlohmann::json::invalid_iterator& e)
|
||||
{
|
||||
std::cout << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user