Skip to content

Commit

Permalink
Update generic-json.md
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenberry committed Sep 30, 2024
1 parent 51f946a commit 2153d67
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/generic-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<glz::json_t>(R"({"foo":"bar"})");
expect(json->contains("foo"));
auto obj = glz::read_json<std::map<std::string, std::string>>(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<glz::opts{}>(v, json));
expect(v == "Beautiful beginning");
```

0 comments on commit 2153d67

Please sign in to comment.