From 2153d678704bd2e815ba88671c6cdebd74ba91de Mon Sep 17 00:00:00 2001 From: Stephen Berry Date: Mon, 30 Sep 2024 09:24:21 -0500 Subject: [PATCH] Update generic-json.md --- docs/generic-json.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/generic-json.md b/docs/generic-json.md index 501436604d..4e2db1802e 100644 --- a/docs/generic-json.md +++ b/docs/generic-json.md @@ -66,3 +66,24 @@ glz::write_json(v, s); expect(s == R"([0,1,2])"); ``` +## Using `json_t` As The Source + +After parsing into a `json_t` it is sometimes desirable to parse into a concrete struct or a portion of the `json_t` into a struct. Glaze allows a `json_t` value to be used as the source where a buffer would normally be passed. + +```c++ +glz::json_t json = glz::read_json(R"({"foo":"bar"})"); +expect(json->contains("foo")); +auto obj = glz::read_json>(json.value()); +// This reads the json_t into a std::map +``` + +Another example: + +```c++ +glz::json_t json{}; +expect(not glz::read_json(json, R"("Beautiful beginning")")); +std::string v{}; +expect(not glz::read(v, json)); +expect(v == "Beautiful beginning"); +``` +