Created
August 14, 2014 23:40
-
-
Save aaronpowell/7dba84a0020c546aaad2 to your computer and use it in GitHub Desktop.
jq - a simple cli for JSON querying
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.stdin.setEncoding('utf8'); | |
var what = process.argv[2] || ''; | |
process.stdin.on('readable', function () { | |
var chunk = process.stdin.read(); | |
if (chunk) { | |
var obj = JSON.parse(chunk); | |
switch(what) { | |
case '.': | |
return console.log(obj); | |
case '': | |
return console.log('nothing to do'); | |
default: | |
var split = what.split('.').filter(function (s) { return !!s; }); | |
return console.log( | |
split.reduce(function (obj, next) { | |
return obj == undefined ? undefined: obj[next]; | |
}, obj) | |
); | |
} | |
} | |
}); | |
process.stdin.on('end', function () { | |
process.stdout.write('dooooooooone\n'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment