简体   繁体   中英

jq - json list of dicts to csv

Input JSON example:

[
  {"name":"Θεμιστοκλής","surname":"Παπαϊωάννου","gender":"male","region":"Greece"}, 
  {"name":"Casian","surname":"Cusin","gender":"male","region":"Romania"}
]

Now with my code I have output as strings:

$ curl -s https://uinames.com/api/?amount=3 | jq '.[] | [.name, .surname] | @csv'
"\"Anamaria\",\"Tămaș\""
"\"Aurora\",\"Coronado\""
"\"Εύηνος\",\"Ελευθερόπουλος\""

What I need:

"Anamaria","Tămaș"
"Aurora","Coronado"
"Εύηνος","Ελευθερόπουλος"

Can anybody explain please what I do wrong?

You should add the -r command-line option when invoking jq.

Example:

$ curl -Ss 'https://uinames.com/api/?amount=3' |
   jq -r '.[] | [.name, .surname] | @csv' 
"Γόργασος","Θεοδωρίδης"
"Marta","Brediceanu"
"Iulian","Bârcă"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM