less than 1 minute read

Wanna read json in csv in order to have a readable output, for example in silver-searcher. Found a solution here

In my case I used:

cat yourjson | jq -r '.[] | join("\t")'
# -r is for getting rid of the double quotes, and join to join the fields with the wanted separator.

I used it in combination with mdbtools extract.

grep -s UserFields settings.csv | perl -pe 's|.*?(\[.*\]).*|\1|g' | perl -pe 's|\\t||g' | ascii2uni -a U -q | jq -r '.[] | join("\t")' > UDF.csv

If you wanna bind everything in alias:

alias RRextract='tablewanted=( settings customFields ranks teamscores contests results );for file in *.ses; do pathfile=$(echo $file | perl -pe "s|.ses||g" | perl -pe "s| ||g" ); mkdir "$pathfile"; mdb-tables -1 "$file"; for value in "${tablewanted[@]}"; do mdb-export -Q -d \\t "$file" $value > "$pathfile/${value}.csv"; done;done;grep -s UserFields "$pathfile/settings.csv" | perl -pe "s|.*?(\[.*\]).*|\1|g" | perl -pe "s|\\t||g" | ascii2uni -a U -q | jq -r '"'"'.[] | join("\t\t")'"'"' > "$pathfile/UDF.csv";rm "$pathfile/settings.csv"'

Tricks with quotes and double quotes from here:

$ echo 'abc'"'"'abc'
abc'abc
$ echo "abc"'"'"abc"
abc"abc

Updated: