json2tsv
--------

Convert JSON to TSV.

json2tsv reads JSON data from stdin.  It outputs each JSON type to a TAB-
Separated Value format per line.


Build and install
-----------------

$ make
# make install


Dependencies
------------

- C compiler (C99).
- libc


Optional dependencies
---------------------

- POSIX make(1) (for Makefile).
- mandoc for documentation: https://mdocml.bsd.lv/


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 field is a single byte and can be:

	a for array
	b for bool
	n for number
	o for object
	s for string
	? for null

Filtering on the first field "nodename" is easy using awk for example.

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?raw_json=1&limit=100' | \
json2tsv | \
awk -F '\t' '
function show() {
	if (length(o["title"]) == 0)
		return;
	print n ". " o["title"] " by " o["author"] " in r/" o["subreddit"];
	print o["url"];
	print "";
}
$1 == ".data.children[].data" {
	show();
	n++;
	delete o;
}
$1 ~ /^\.data\.children\[\]\.data\.[a-zA-Z0-9_]*$/ {
	o[substr($1, 23)] = $3;
}
END {
	show();
}'


License
-------

ISC, see LICENSE file.


Author
------

Hiltjo Posthuma <hiltjo@codemadness.org>
