Quick Start =========== [Updated underscore.js to v1.3.1.](http://documentcloud.github.com/underscore/) 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.](http://johnattebury.com/blog/2011/06/spidermonkey-jsawk-resty-on-snow-leopard/) You need to have the `js` interpreter installed. On a Debian system you can install it with the following command: apt-get install spidermonkey-bin Or you can [build it from source](http://www.mozilla.org/js/spidermonkey/). 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](http://github.com/micha/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. Usage ===== jsawk [OPTIONS] [SCRIPT] OPTIONS ------- -h Print short help page and exit. -n Suppress printing of JSON result set. -q Filter JSON through the specified JSONQuery query. If multiple '-q' options are specified then each query will be performed in turn, in the order in which they appeared on the command line. -v Set global variable `name` to `value` in the script environment. -f Load and run the specified JavaScript file prior to processing JSON. This option can be specified multiple times to load multiple JavaScript libraries. -b