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: README.md
+98-1Lines changed: 98 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,14 +90,15 @@ To simplify the engineering, we make some assumptions.
90
90
- We assume AVX2 support which is available in all recent mainstream x86 processors produced by AMD and Intel. No support for non-x86 processors is included though it can be done. We plan to support ARM processors (help is invited).
91
91
- We only support GNU GCC and LLVM Clang at this time. There is no support for Microsoft Visual Studio, though it should not be difficult (help is invited).
92
92
- In cases of failure, we just report a failure without any indication as to the nature of the problem. (This can be easily improved without affecting performance.)
93
+
- As allowed by the specification, we allow repeated keys within an object (other parsers like sajson do the same).
93
94
94
95
*We do not aim to provide a general-purpose JSON library.* A library like RapidJSON offers much more than just parsing, it helps you generate JSON and offers various other convenient functions. We merely parse the document.
95
96
96
97
97
98
## Features
98
99
99
100
- The input string is unmodified. (Parsers like sajson and RapidJSON use the input string as a buffer.)
100
-
- We parse integers and floating-point numbers as separate types which allows us to support large 64-bit integers.
101
+
- We parse integers and floating-point numbers as separate types which allows us to support large 64-bit integers in [-9223372036854775808,9223372036854775808). Among the parsers that differentiate between integers and floating-point numbers, not all support 64-bit integers. (For example, sajson stores integers larger than 2147483648 as floating-point numbers.)
101
102
- We do full UTF-8 validation as part of the parsing. (Parsers like fastjson, gason and dropbox json11 do not do UTF-8 validation.)
102
103
- We fully validate the numbers. (Parsers like gason and ultranjson will accept `[0e+]` as valid JSON.)
103
104
- We validate string content for unescaped characters. (Parsers like fastjson and ultrajson accept unescaped line breaks and tags in strings.)
@@ -111,6 +112,102 @@ The parser works in three stages:
111
112
- Stage 3. (Structure building) Involves constructing a "tree" of sort to navigate through the data. Strings and numbers are parsed at this stage.
112
113
113
114
115
+
## Navigating the parsed document
116
+
117
+
Here is a code sample to dump back the parsed JSON to a string:
118
+
119
+
```c
120
+
ParsedJson::iterator pjh(pj);
121
+
if (!pjh.isOk()) {
122
+
std::cerr << " Could not iterate parsed result. " << std::endl;
123
+
return EXIT_FAILURE;
124
+
}
125
+
compute_dump(pj);
126
+
//
127
+
// where compute_dump is :
128
+
129
+
void compute_dump(ParsedJson::iterator &pjh) {
130
+
if (pjh.is_object()) {
131
+
std::cout << "{";
132
+
if (pjh.down()) {
133
+
pjh.print(std::cout); // must be a string
134
+
std::cout << ":";
135
+
pjh.next();
136
+
compute_dump(pjh); // let us recurse
137
+
while (pjh.next()) {
138
+
std::cout << ",";
139
+
pjh.print(std::cout);
140
+
std::cout << ":";
141
+
pjh.next();
142
+
compute_dump(pjh); // let us recurse
143
+
}
144
+
pjh.up();
145
+
}
146
+
std::cout << "}";
147
+
} else if (pjh.is_array()) {
148
+
std::cout << "[";
149
+
if (pjh.down()) {
150
+
compute_dump(pjh); // let us recurse
151
+
while (pjh.next()) {
152
+
std::cout << ",";
153
+
compute_dump(pjh); // let us recurse
154
+
}
155
+
pjh.up();
156
+
}
157
+
std::cout << "]";
158
+
} else {
159
+
pjh.print(std::cout); // just print the lone value
160
+
}
161
+
}
162
+
```
163
+
164
+
The following function will find all user.id integers:
0 commit comments