This commit is contained in:
nlohmann committed 2026-10-21 10:31:00 +00:00
1 parent be4d0a6f4b
commit 90f0c9d411
714 files changed
+22067 -622

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
#include <iostream>
#include <nlohmann/json_view.hpp>
using json_document = nlohmann::json_document;
int main()
{
// scan a (possibly large) array of readings for the first one over a
// threshold; the loop stops at end() as soon as one is found, and only
// the matching reading is ever materialized
json_document readings = json_document::parse("[12, 18, 25, 31, 9]");
const auto values = readings.root();
auto it = values.begin();
for (; it != values.end(); ++it)
{
if (it->materialize().get<int>() > 20)
{
break;
}
}
if (it != values.end())
{
std::cout << "first reading over 20: " << it->materialize().dump() << '\n';
}
}