2018-07-13 16:08:24 +10:00
|
|
|
#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 {
|
2018-08-05 14:42:02 +10:00
|
|
|
std::cout << cruft::json::pointer::resolve (query, *root) << '\n';
|
2018-07-13 16:08:24 +10:00
|
|
|
} catch (std::exception const &x) {
|
|
|
|
std::cerr << "error" << x.what () << '\n';
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|