CCCPaste

BASH jq convert JSON to CSV

#json to csv with jq
#get key headers
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[0]|(.name)|keys|@csv'

#get values
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[]|(.name)|flatten|@csv'

#using a different delimiter - note that this may not escape out characters the same as csv
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[]|(.name)|flatten|join("|")'