Quick Start
If you use Jsawk and want to help maintain it, please let me know and I'll add you to the repo.
Updated underscore.js to v1.8.2.
Jsawk is like awk, but for JSON. You work with an array of JSON objects read from stdin, filter them using JavaScript to produce a results array that is printed to stdout. You can use this as a filter to manipulate data from a REST JSON web service, for example, in a shell script. Also, you can suppress JSON output and use the built-in printing functions to translate your JSON input to other formats and send that to stdout, to be piped to other processes. You can load JavaScript libraries on the command line to increase your processing power, and other things.
Setup
This is a great blog post on setup and basic use of jsawk and resty, thanks to @johnattebury.
You need to have the js interpreter installed. Your best bet is to navigate to
the mozilla site download and build the source
based on the maintained documentation there.
Ready? Go.
Install
First, get the jsawk script:
curl -L http://github.com/micha/jsawk/raw/master/jsawk > jsawk
Then make it executable and put it somewhere in your path:
chmod 755 jsawk && mv jsawk ~/bin/
Use
Now you can do some stuff with JSON data. Here's an example using data from a REST service that serves JSON (we use resty to do the HTTP requests):
resty http://example.com:8080/data*.json
GET /people/47 | jsawk 'this.favoriteColor = "blue"' | PUT /people/47
This would do a GET request on the resource /data/people/47.json, which
would result in a JSON object. Then jsawk takes the JSON via stdin and for
each JSON object it runs the little snippet of JavaScript, setting the
favoriteColor property to "blue", in this case. The modified JSON is then
output via stdout to resty again, which does the PUT request to update
the resource.