HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
micha
jsawk
Shell2009–2015
micha / jsawk

jsawk

Like awk, but for JSON.

13Distinct people
13Mentions
0Explicit recommenders
1.4KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Like awk, but for JSON.

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 12:54:37 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year13 dated mentions

Observed mentions: 2009-05-26 01:51:56 UTC to 2015-11-02 09:17:01 UTC.

0123452009-01-01 00:00:00 UTC to 2010-01-01 00:00:00 UTC (exclusive): 2 mentions; 2 submissions, 0 comments20092010-01-01 00:00:00 UTC to 2011-01-01 00:00:00 UTC (exclusive): 2 mentions; 1 submissions, 1 comments2011-01-01 00:00:00 UTC to 2012-01-01 00:00:00 UTC (exclusive): 5 mentions; 0 submissions, 5 comments2012-01-01 00:00:00 UTC to 2013-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments20122013-01-01 00:00:00 UTC to 2014-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-01-01 00:00:00 UTC to 2015-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2015-01-01 00:00:00 UTC to 2016-01-01 00:00:00 UTC (exclusive): 1 mentions; 1 submissions, 0 comments2015

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20092009-01-01 00:00:00 UTC2010-01-01 00:00:00 UTC220
20102010-01-01 00:00:00 UTC2011-01-01 00:00:00 UTC211
20112011-01-01 00:00:00 UTC2012-01-01 00:00:00 UTC505
20122012-01-01 00:00:00 UTC2013-01-01 00:00:00 UTC303
20132013-01-01 00:00:00 UTC2014-01-01 00:00:00 UTC000
20142014-01-01 00:00:00 UTC2015-01-01 00:00:00 UTC000
20152015-01-01 00:00:00 UTC2016-01-01 00:00:00 UTC110

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
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. Usage jsawk [OPTIONS] [SCRIPT] OPTIONS ------- -b <script> | -a <script> Run the specified snippet of JavaScript before (-b) or after (-a) processing JSON input. The `this` object is set to the whole JSON array or object. This is used to preprocess (-b) or postprocess (-a) the JSON array before or after the main script is applied. This option can be specified multiple times to define multiple before/after scripts, which will be applied in the order they appeared on the command line. -f <file> Load and run the specified JavaScript file prior to processing JSON. This option can be specified multiple times to load multiple JavaScript libraries. -h Print short help page and exit. -i <file> Read input JSON from `file` instead of stdin. -j <jsbin> Specify path to spidermonkey js binary. -n Suppress printing of JSON result set. -q <query> 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. -s <string> Use `string` for input JSON instead of stdin. -v <name=value> Set global variable `name` to `value` in the script environment. SCRIPT ------ This is a snippet of JavaScript that will be run on each element of the input array, if input is a JSON array, or on the object if it's an object. For each iteration, the `this` object is set to the current element. Using A Specific JS Binary The path to the js binary can be specified in two different ways: the -j command line option (see above) the JS environment variable Additionally, jsawk will source the following files at startup if they exist: /etc/jsawkrc ~/.jsawkrc These files can be used to export the JS environment variable. Jsawk Scripting Jsawk is intended to serve the purpose that is served by awk in the shell environment, but instead of working with words and lines of text, it works with JavaScript objects and arrays of objects. In awk, a text file is split into an array of "records", each of which being an array of "fields". The awk script that is specified on the command line is run once for each record in the array, with the $1, $2, etc. variables set to the various fields in the record. The awk script can set variables, perform calculations, do various text-munging things, and print output. This printing capablity makes awk into a filter, taking text input, transforming it record by record, printing out the resulting modified records at the end. Jsawk is similar, but in jsawk records are elements of the JSON input array (if the input was a single object then there is a single record consisting of that object). The jsawk script is run once for each record object, with the this object set to the current record. So here the properties of the record object are equivalent to the $1, $2, etc. in awk. The jsawk script can then modify the record, perform calculations, do things. However, instead of printing the modified record, the modified record is returned. At then end, if the -n option was not specified, the resulting array is printed as JSON to stdout. Jsawk JavaScript Environment Jsawk uses the Spidermonkey JavaScript interpreter, so you have access to all of the Spidermonkey functions and whatnot. Additionally, the following functions and properties are available from within a jsawk script: PROPERTIES ---------- window The global object. IS The input set. RS The result set. _ The underscore.js object. $_ The current record index (corresponding to the index of the element in the IS array). $$ The current record object (global variable corresponding to the `this` object in the script scope). METHODS ------- forEach(array, string) Compiles 'string' into a function and iterates over the 'array', running the function once for each element. The function has access to the special variables 'index' and 'item' which are,
Read the full README on GitHub

What Hacker News says

13 sources
The gist—as I understand it—is that Unix programs are essentially all equivalent to functions : ([String], TextStream) -> (TextStream, TextStream) which limits how one can tie them together and causes a proliferation of text-processing tools (awk, sed, grep, cut, &c &c) which is not as elegant as functional programming. There are already some Unix command-line tools that work on structured data as mentioned, e.g. jsawk[1] is a tool inspired by awk whose scripting language is JavaScript and which works on JSON. As an aside, I'd like to see people experiment with these concepts on an OS level while consciously targeting Xen or other virtualization systems. Already, Haskell can run barebones on Xen using HaLVM[2] and the successor to Plan 9, Inferno[3], was a virtual machine that could run either on bare metal or inside another OS. I can ima
Read the rest
gine an entirely new OS would meet some resistance—like Plan 9 did—but supplying an OS intended to be virtualized would let people experiment freely within their existing OS. [1]: https://github.com/micha/jsawk [2]: http://halvm.org/wiki/ [3]: http://code.google.com/p/inferno-os/
In Functional programming and the death of the Unix Way
My biggest issue with XML is "XML misunderstands Unix philosophy". You can't easily use cut, awk and grep with XML without having a million of edge case to handle. There are some tools like XMLStarlet, xsltproc or xalan. But you can't safely extract content from XML files with standards tools even if you use the XML extension for gawk. You could argue that XML documents are complex and cannot be described using simple comma separated. Maybe but some many XML documents are just there to store simple key,value data. And now, we have "jsawk" (https://github.com/micha/jsawk) for parsing JSON under your terminal...
In You probably misunderstand XML

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.