Advertisement
metalx1000

BASH jq convert JSON to CSV

Aug 16th, 2022
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.42 KB | Source Code | 0 0
  1. #json to csv with jq
  2. #get key headers
  3. wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[0]|(.name)|keys|@csv'
  4.  
  5. #get values
  6. wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[]|(.name)|flatten|@csv'
  7.  
  8. #using a different delimiter - note that this may not escape out characters the same as csv
  9. wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[]|(.name)|flatten|join("|")'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement