You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/partial-read.md
+64-70
Original file line number
Diff line number
Diff line change
@@ -2,18 +2,17 @@
2
2
3
3
At times it is not necessary to read the entire JSON document, but rather just a header or some of the initial fields. Glaze provides multiple solutions:
4
4
5
-
-`partial_read` in `glz::opts`
6
5
-`partial_read` in `glz::meta`
7
-
- Partial reading via [JSON Pointer syntax](./json-pointer-syntax.md)
8
-
9
-
> [!NOTE]
10
-
>
11
-
> If you wish partial reading to work on nested objects, you must also turn on `.partial_read_nested = true` in `glz::opts`.
6
+
- Partial reading via [JSON Pointer syntax](./json-pointer-syntax.md)
12
7
13
8
# Partial reading with glz::opts
14
9
15
10
`partial_read` is a compile time flag in `glz::opts` that indicates only existing array and object elements should be read into, and once the memory has been read, parsing returns without iterating through the rest of the document.
16
11
12
+
> [!NOTE]
13
+
>
14
+
> Once any sub-object is read, the parsing will finish. This ensures high performance with short circuiting.
15
+
17
16
> A [wrapper](./wrappers.md) by the same name also exists.
18
17
19
18
Example: read only the first two elements into a `std::tuple`
@@ -47,7 +46,7 @@ expect(obj.size() == 1);
47
46
expect(obj.at("2") = 2);
48
47
```
49
48
50
-
Example: read only the fields present in a struct
49
+
Example: read only the fields present in a struct and then short circuit the parse
51
50
52
51
```c++
53
52
struct partial_struct
@@ -65,51 +64,6 @@ expect(obj.string == "ha!");
65
64
expect(obj.integer == 400);
66
65
```
67
66
68
-
# Partial reading with glz::meta
69
-
70
-
Glaze allows a `partial_read` flag that can be set to `true` within the glaze metadata.
71
-
72
-
```json
73
-
{
74
-
"id": "187d3cb2-942d-484c-8271-4e2141bbadb1",
75
-
"type": "message_type"
76
-
.....
77
-
// the rest of the large JSON
78
-
}
79
-
```
80
-
81
-
When `partial_read` is `true`, parsing will end once all the keys defined in the struct have been parsed.
82
-
83
-
## partial_read_nested
84
-
85
-
If your object that you wish to only read part of is nested within other objects, set `partial_read_nested = true` so that Glaze will properly parse the parent objects by skipping to the end of the partially read object.
0 commit comments