2
2
3
3
* If you use Jsawk and want to help maintain it, please let me know and I'll add you to the repo.*
4
4
5
- [ Updated underscore.js to v1.6.0 .] ( http://documentcloud.github.com/underscore/ )
5
+ [ Updated underscore.js to v1.8.2 .] ( http://documentcloud.github.com/underscore/ )
6
6
7
7
Jsawk is like awk, but for JSON. You work with an array of JSON objects
8
8
read from stdin, filter them using JavaScript to produce a results array
@@ -18,10 +18,10 @@ increase your processing power, and other things.
18
18
[ This is a great blog post on setup and basic use of jsawk and resty, thanks
19
19
to @johnattebury .] ( http://johnattebury.com/blog/2011/06/spidermonkey-jsawk-resty-on-snow-leopard/ )
20
20
21
- You need to have the ` js ` interpreter installed. Your best bet is to navigate to
22
- the mozilla site [ download and build the source] ( https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey )
21
+ You need to have the ` js ` interpreter installed. Your best bet is to navigate to
22
+ the mozilla site [ download and build the source] ( https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey )
23
23
based on the maintained documentation there.
24
-
24
+
25
25
Ready? Go.
26
26
27
27
## Install
@@ -79,7 +79,7 @@ the resource.
79
79
80
80
-j <jsbin>
81
81
Specify path to spidermonkey js binary.
82
-
82
+
83
83
-n
84
84
Suppress printing of JSON result set.
85
85
@@ -90,7 +90,7 @@ the resource.
90
90
91
91
-s <string>
92
92
Use `string` for input JSON instead of stdin.
93
-
93
+
94
94
-v <name=value>
95
95
Set global variable `name` to `value` in the script environment.
96
96
@@ -303,7 +303,7 @@ JSON-to-JSON Transformations
303
303
304
304
These examples transform the input JSON, modifying it and returning the
305
305
modified JSON as output on stdout to be piped elsewhere. Transformations of
306
- this type are generally done with a script that follows one of these simple
306
+ this type are generally done with a script that follows one of these simple
307
307
patterns:
308
308
309
309
1 . Modify the ` this ` object in place (no ` return ` statement necessary).
@@ -360,8 +360,8 @@ return value in the output set.
360
360
### JSON Grep: Select Certain Elements From Input ###
361
361
362
362
Sometimes you want to use awk to select certain records from the input set,
363
- leaving the rest unchanged. This is like the ` grep ` pattern of operation. In
364
- this example we will extract all the records corresponding to people who are
363
+ leaving the rest unchanged. This is like the ` grep ` pattern of operation. In
364
+ this example we will extract all the records corresponding to people who are
365
365
over 30 years old.
366
366
367
367
cat /tmp/t | jsawk 'if (this.age <= 30) return null'
@@ -377,7 +377,7 @@ a whole, somewhat similar to the way aggregate functions like `SUM()` or
377
377
` COUNT() ` work in SQL. These types of operations fall under a few basic
378
378
patterns.
379
379
380
- 1 . Use a before script (` -b ` option) to do things to the JSON input before
380
+ 1 . Use a before script (` -b ` option) to do things to the JSON input before
381
381
transformations are done by the main script.
382
382
2 . Use an after script (` -a ` option) to do things to the JSON result set
383
383
after all transformations are completed by the main script.
@@ -430,7 +430,7 @@ alphabetically.
430
430
431
431
Notice the use of JSONQuery to drill down into the JSON objects, an "after"
432
432
script to collate the results, and everything piped to the Unix ` sort `
433
- tool to remove duplicate entries and do the lexical ordering. This is
433
+ tool to remove duplicate entries and do the lexical ordering. This is
434
434
starting to show the power of the awk-like behavior now.
435
435
436
436
### Return a Boolean Value
@@ -448,8 +448,8 @@ zero for success.
448
448
JSON Pretty-Printing
449
449
====================
450
450
451
- [ Resty] ( http://github.com/micha/resty ) includes the ` pp ` script that will
452
- pretty-print JSON for you. You just need to install the JSON perl module
451
+ [ Resty] ( http://github.com/micha/resty ) includes the ` pp ` script that will
452
+ pretty-print JSON for you. You just need to install the JSON perl module
453
453
from CPAN. Use it like this:
454
454
455
455
GET /blogs.json | jsawk -q '..author' | pp
0 commit comments