jtq - json2tsv - JSON to TSV converter
(HTM) git clone git://git.codemadness.org/json2tsv
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
jtq (676B)
---
1 #!/bin/sh
2 args=$(getopt n $*)
3 if [ $? -ne 0 ]; then
4 echo "usage: $0 [-n] [awk expressions...]" >&2
5 exit 1
6 fi
7
8 nflag=""
9 set -- $args
10 while [ $# -ne 0 ]; do
11 case "$1" in
12 -n)
13 nflag="-n"; shift;; # json2tsv -n: show indices for array types.
14 --)
15 shift; break;;
16 esac
17 done
18
19 e="$@" # awk expressions
20 if [ $# -gt 0 ]; then
21 statusfile=$(mktemp)
22 # simulate pipefail if JSON data is invalid.
23 { json2tsv ${nflag} -r -F '\x1f' -R '\x1e'; echo $? >"${statusfile}"; } | \
24 LC_ALL=C awk "BEGIN { FS = \"\x1f\"; RS = \"\x1e\"; }${e}"
25 statuscode="$(cat "${statusfile}")$?"
26 rm -f "${statusfile}"
27 test "${statuscode}" = "00"
28 else
29 # show the nodes per line.
30 json2tsv ${nflag}
31 fi