Update jsonpointer tool to use new API
This commit is contained in:
parent
eb5a1ea113
commit
06d6636b97
|
@ -50,35 +50,26 @@ int main(int argc, char *argv[]) {
|
|||
<< std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const char *filename = argv[1];
|
||||
auto [p, error] = simdjson::padded_string::load(filename);
|
||||
if (error) {
|
||||
std::cerr << "Could not load the file " << filename << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
simdjson::ParsedJson pj;
|
||||
int res =
|
||||
simdjson::json_parse(p, pj); // do the parsing, return false on error
|
||||
if (res) {
|
||||
std::cerr << " Parsing failed with error " << simdjson::error_message(res)
|
||||
<< std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
auto [doc, error] = simdjson::document::load(filename);
|
||||
if (error) { std::cerr << "Error parsing " << filename << ": " << error << std::endl; }
|
||||
|
||||
std::cout << "[" << std::endl;
|
||||
for (int idx = 2; idx < argc; idx++) {
|
||||
const char *jsonpath = argv[idx];
|
||||
simdjson::ParsedJson::Iterator it(pj.doc);
|
||||
if (it.move_to(std::string(jsonpath))) {
|
||||
std::cout << "{\"jsonpath\": \"" << jsonpath << "\"," << std::endl;
|
||||
std::cout << "\"value\":";
|
||||
compute_dump(it);
|
||||
std::cout << "}" << std::endl;
|
||||
const char *json_pointer = argv[idx];
|
||||
auto [value, pointer_error] = doc[json_pointer];
|
||||
std::cout << "{\"jsonpath\": \"" << json_pointer << "\"";
|
||||
if (pointer_error) {
|
||||
std::cout << ",\"error\":\"" << pointer_error << "\"";
|
||||
} else {
|
||||
std::cout << "null" << std::endl;
|
||||
std::cout << ",\"value\":" << value;
|
||||
}
|
||||
std::cout << "}";
|
||||
if (idx + 1 < argc) {
|
||||
std::cout << "," << std::endl;
|
||||
std::cout << ",";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::cout << "]" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue