forked from TeachingOW/simdjson-quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.cpp
More file actions
62 lines (50 loc) · 1.46 KB
/
project.cpp
File metadata and controls
62 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "simdjson.h"
#include <iostream>
#include <unordered_map>
using namespace simdjson;
using namespace std;
unordered_map<string, string> ht;
void get_type(string k, ondemand::value element) {
std::string type_of_value = "";
switch (element.type()) {
case ondemand::json_type::array:
for (auto child : element.get_array()) {
get_type(k + "[] ", child.value());
}
// Add something
break;
case ondemand::json_type::object:
for (auto field : element.get_object()) {
//stringstream s;
//s << k << "." << field.key();
std::string_view s(field.escaped_key());
get_type(k+"."+string(s), field.value());
}
break;
case ondemand::json_type::number:
type_of_value = "number";
break;
case ondemand::json_type::string:
type_of_value = "string";
break;
case ondemand::json_type::boolean:
type_of_value = "boolean";
break;
case ondemand::json_type::null:
if (element.is_null()) {
type_of_value = "null";
}
break;
}
ht.insert(make_pair(k, type_of_value));
}
int main(void) {
ondemand::parser parser;
padded_string json = padded_string::load("cars.json");
ondemand::document cars = parser.iterate(json);
ondemand::value v = cars;
get_type("", v);
for (auto k : ht) {
cout << k.first << " " << k.second << "\n";
}
}