libcruft-util/tools/json-pointer.cpp
Danny Robson f6056153e3 rename root namespace from util to cruft
This places, at long last, the core library code into the same namespace
as the extended library code.
2018-08-05 14:42:02 +10:00

35 lines
652 B
C++

#include "json/tree.hpp"
#include "json/pointer.hpp"
#include <iostream>
enum {
ARG_SELF,
ARG_QUERY,
ARG_INPUT,
NUM_ARGS,
};
int
main (int argc, char **argv)
{
if (argc != NUM_ARGS) {
std::cerr << argv[ARG_SELF] << " <query> <input>\n";
return EXIT_FAILURE;
}
auto const root = json::tree::parse (argv[ARG_INPUT]);
std::string const query = argv[ARG_QUERY];
try {
std::cout << cruft::json::pointer::resolve (query, *root) << '\n';
} catch (std::exception const &x) {
std::cerr << "error" << x.what () << '\n';
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}