Skip to content

Instantly share code, notes, and snippets.

@justgord
Created September 5, 2011 05:46
Show Gist options
  • Save justgord/1194181 to your computer and use it in GitHub Desktop.
Save justgord/1194181 to your computer and use it in GitHub Desktop.
handy command line util for looking into JSON files - based on JSONPath npm module
#!/usr/bin/env node
var fs = require('fs');
var jsonpath = require('JSONPath');
if (process.argv.length<3)
{
console.log('usage: jsonpath json_filename json_path_expr');
exit;
}
var sfile = process.argv[2];
var spath = process.argv[3];
var cont = fs.readFileSync(sfile);
var obj = JSON.parse(cont);
var res = jsonpath.eval(obj, spath);
console.log(res);
@zwegner
Copy link

zwegner commented Apr 2, 2013

Here's a quick fix if your result object has too many layers of nesting, and console.log truncates them with [Object]. Change the last line to:

console.log(JSON.stringify(res));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment