json2tsv - convert JSON to TSV
------------------------------

json2tsv reads JSON data from stdin.  It outputs each JSON type to a TAB-
Separated Value format per line.  The -n flag can be used to show the indices
for array types (by default off).


TAB-Separated Value format
--------------------------

The output format per line is:

	nodename<TAB>type<TAB>value<LF>

The nodename and value are escaped (\n, \t and \\).  Control-characters are
removed.

The type can be: o (for object), a (for array), p (for primitive such as true,
false, null, a number) or s (for string).

Then filtering is easy using some awk script on the node "selector".

See the json2tsv(1) man page for the full documentation.


Example
-------

An usage example to parse JSON posts of reddit.com and format them to a
plain-text list using awk:


#!/bin/sh
curl -s -H 'User-Agent:' 'https://old.reddit.com/.json' | \
json2tsv | \
awk 'BEGIN {
	FS = OFS = "\t";
	n = 0;
	title = author = subreddit = "";
}
function show() {
	if (length(title) == 0)
		return;
	print n ". " title " by " author " in r/" subreddit;
	print url;
	print "";
}
$1 == ".data.children[].data" {
	show();
	n++;
	title = url = author = subreddit = "";
}
$1 == ".data.children[].data.url" { url = $3; }
$1 == ".data.children[].data.title" { title = $3; }
$1 == ".data.children[].data.author" { author = $3; }
$1 == ".data.children[].data.subreddit" { subreddit = $3; }
END {
	show();
}'


License
-------

ISC, see LICENSE file.
