3

I am trying to create a csv file with headers from a json using jq.

I have the following snippet https://jqplay.org/s/H_U5mxbTFW

Question: How can I print the values of peerings > accept_vpc_info > tenant_id and peerings > accept_vpc_info > vpc_id

What i tried:

The JSON

{
    "peerings": [
        {
            "accept_vpc_info": {
                "tenant_id": "184a5",
                "vpc_id": "0d11f"
            },
            "created_at": "2018-11-07T08:53:43",
            "description": null,
            "id": "0b19d",
            "name": "NAME1",
            "request_vpc_info": {
                "tenant_id": "08a7b",
                "vpc_id": "1645f"
            },
            "status": "ACTIVE",
            "updated_at": "2018-11-07T09:47:44"
        },
        {
            "accept_vpc_info": {
                "tenant_id": "067eb",
                "vpc_id": "17944"
            },
            "created_at": "2019-06-12T08:29:08",
            "description": null,
            "id": "0d34a",
            "name": "NAME2",
            "request_vpc_info": {
                "tenant_id": "0fd7b",
                "vpc_id": "102c9"
            },
            "status": "ACTIVE",
            "updated_at": "2019-06-12T12:04:56"
        },
        {
            "accept_vpc_info": {
                "tenant_id": "0ae21",
                "vpc_id": "071c4"
            },
            "created_at": "2019-02-21T09:07:35",
            "description": null,
            "id": "173e2",
            "name": "NAME3",
            "request_vpc_info": {
                "tenant_id": "05a21",
                "vpc_id": "0586e"
            },
            "status": "ACTIVE",
            "updated_at": "2019-02-21T09:10:41"
        }
            ]
    }

JQ:

.[] | flatten | map({created_at,description,id,name,status,updated_at}) | (first | keys_unsorted) as $keys | map([to_entries[] | .value]) as $rows | $keys,$rows[] | join (", ")

It is working without adding accept_vpc_info and request_vpc_info.

I try to add these as header: accept_vpc_info, accept_vpc_info_tenant_id, accept_vpc_info_vpc_id, created_at, description, id, name,request_vpc_info, request_vpc_info_tenant_id, request_vpc_info_vpc_id, status, updated_at

Something like this:

"accept_vpc_info__tenant_id","accept_vpc_info__vpc_id","created_at","description","id","name","request_vpc_info__tenant_id","request_vpc_info__vpc_id","status","updated_at"
"184a5","0d11f","2018-11-07T08:53:43","null","0b19d","NAME1","08a7b","1645f","ACTIVE","2018-11-07T09:47:44"
"067eb","17944","2019-06-12T08:29:08","null","0d34a","NAME2","0fd7b","102c9","ACTIVE","2019-06-12T12:04:56"
"0ae21","071c4","2019-02-21T09:07:35","null","173e2","NAME3","05a21","0586e","ACTIVE","2019-02-21T09:10:41"

How can I print also the values of peerings > accept_vpc_info > tenant_id and peerings > accept_vpc_info > vpc_id ?

Thank you

4 Answers 4

3

With jq you could run something along the lines of:

  1. (Assuming you want to select just some fields) create a jq filter "x.jq"
["name","id","tenant","vpc"] ,      ### the csv header
(.peerings[]                        ### for all in peerings list
  | [ .name,
      .id,
      .accept_vpc_info.tenant_id,
      .accept_vpc_info.vpc_id 
    ]
) | @csv
  1. run it!
$  jq -rf x.jq  ex.json 
"name","id","tenant","vpc"
"NAME1","0b19d","184a5","0d11f"
"NAME2","0d34a","067eb","17944"
"NAME3","173e2","0ae21","071c4"
3

Using csvkit, you can translate directly Json to CVS

$ in2csv -k peerings ex.json
accept_vpc_info/tenant_id,accept_vpc_info/vpc_id,created_at,description,id,name,request_vpc_info/tenant_id,request_vpc_info/vpc_id,status,updated_at
184a5,0d11f,2018-11-07T08:53:43,,0b19d,NAME1,08a7b,1645f,ACTIVE,2018-11-07T09:47:44
067eb,17944,2019-06-12T08:29:08,,0d34a,NAME2,0fd7b,102c9,ACTIVE,2019-06-12T12:04:56
0ae21,071c4,2019-02-21T09:07:35,,173e2,NAME3,05a21,0586e,ACTIVE,2019-02-21T09:10:41

See in2csv manual for more options and details.

2

I generally dislike using two tools when one should do the job, but you might consider using Miller's (limited) JSON to CSV conversion capabilities - this seems to be one case where the limitations actually help (since it flattens everything by default, and constructs the flattened field names for you):

$ mlr --prepipe 'jq ".[]"' --ijson --jflatsep __  --ocsv --quote-all cat file.json
"accept_vpc_info__tenant_id","accept_vpc_info__vpc_id","created_at","description","id","name","request_vpc_info__tenant_id","request_vpc_info__vpc_id","status","updated_at"
"184a5","0d11f","2018-11-07T08:53:43","","0b19d","NAME1","08a7b","1645f","ACTIVE","2018-11-07T09:47:44"
"067eb","17944","2019-06-12T08:29:08","","0d34a","NAME2","0fd7b","102c9","ACTIVE","2019-06-12T12:04:56"
"0ae21","071c4","2019-02-21T09:07:35","","173e2","NAME3","05a21","0586e","ACTIVE","2019-02-21T09:10:41"
1

This problem is far easier than it looks and can be solved in the general case just by running jq twice.

Consider the following pipeline:

VOICES="$(aws polly describe-voices)"
jq -r -s --argfile e <(echo "$VOICES" |\
    jq '.[][] | select(.["SupportedEngines"][] == "neural") | to_entries')\
         '[$e[0][].key], ($e[($e | keys)[]]|[.[].value|tostring]) | @tsv' <<< "$VOICES"

Which for e.g.:

{
    "Voices": [
        {
            "Gender": "Male",
            "Id": "Kevin",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Kevin",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Filiz",
            "LanguageCode": "tr-TR",
            "LanguageName": "Turkish",
            "Name": "Filiz",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Elin",
            "LanguageCode": "sv-SE",
            "LanguageName": "Swedish",
            "Name": "Elin",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Astrid",
            "LanguageCode": "sv-SE",
            "LanguageName": "Swedish",
            "Name": "Astrid",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Tatyana",
            "LanguageCode": "ru-RU",
            "LanguageName": "Russian",
            "Name": "Tatyana",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Maxim",
            "LanguageCode": "ru-RU",
            "LanguageName": "Russian",
            "Name": "Maxim",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Carmen",
            "LanguageCode": "ro-RO",
            "LanguageName": "Romanian",
            "Name": "Carmen",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Ines",
            "LanguageCode": "pt-PT",
            "LanguageName": "Portuguese",
            "Name": "Inês",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Cristiano",
            "LanguageCode": "pt-PT",
            "LanguageName": "Portuguese",
            "Name": "Cristiano",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Vitoria",
            "LanguageCode": "pt-BR",
            "LanguageName": "Brazilian Portuguese",
            "Name": "Vitória",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Ricardo",
            "LanguageCode": "pt-BR",
            "LanguageName": "Brazilian Portuguese",
            "Name": "Ricardo",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Camila",
            "LanguageCode": "pt-BR",
            "LanguageName": "Brazilian Portuguese",
            "Name": "Camila",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Maja",
            "LanguageCode": "pl-PL",
            "LanguageName": "Polish",
            "Name": "Maja",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Jan",
            "LanguageCode": "pl-PL",
            "LanguageName": "Polish",
            "Name": "Jan",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Jacek",
            "LanguageCode": "pl-PL",
            "LanguageName": "Polish",
            "Name": "Jacek",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Ewa",
            "LanguageCode": "pl-PL",
            "LanguageName": "Polish",
            "Name": "Ewa",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Ola",
            "LanguageCode": "pl-PL",
            "LanguageName": "Polish",
            "Name": "Ola",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Ruben",
            "LanguageCode": "nl-NL",
            "LanguageName": "Dutch",
            "Name": "Ruben",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Lotte",
            "LanguageCode": "nl-NL",
            "LanguageName": "Dutch",
            "Name": "Lotte",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Laura",
            "LanguageCode": "nl-NL",
            "LanguageName": "Dutch",
            "Name": "Laura",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Ida",
            "LanguageCode": "nb-NO",
            "LanguageName": "Norwegian",
            "Name": "Ida",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Liv",
            "LanguageCode": "nb-NO",
            "LanguageName": "Norwegian",
            "Name": "Liv",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Seoyeon",
            "LanguageCode": "ko-KR",
            "LanguageName": "Korean",
            "Name": "Seoyeon",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Kazuha",
            "LanguageCode": "ja-JP",
            "LanguageName": "Japanese",
            "Name": "Kazuha",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Tomoko",
            "LanguageCode": "ja-JP",
            "LanguageName": "Japanese",
            "Name": "Tomoko",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Takumi",
            "LanguageCode": "ja-JP",
            "LanguageName": "Japanese",
            "Name": "Takumi",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Mizuki",
            "LanguageCode": "ja-JP",
            "LanguageName": "Japanese",
            "Name": "Mizuki",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Bianca",
            "LanguageCode": "it-IT",
            "LanguageName": "Italian",
            "Name": "Bianca",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Giorgio",
            "LanguageCode": "it-IT",
            "LanguageName": "Italian",
            "Name": "Giorgio",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Carla",
            "LanguageCode": "it-IT",
            "LanguageName": "Italian",
            "Name": "Carla",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Karl",
            "LanguageCode": "is-IS",
            "LanguageName": "Icelandic",
            "Name": "Karl",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Dora",
            "LanguageCode": "is-IS",
            "LanguageName": "Icelandic",
            "Name": "Dóra",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Mathieu",
            "LanguageCode": "fr-FR",
            "LanguageName": "French",
            "Name": "Mathieu",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Lea",
            "LanguageCode": "fr-FR",
            "LanguageName": "French",
            "Name": "Léa",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Celine",
            "LanguageCode": "fr-FR",
            "LanguageName": "French",
            "Name": "Céline",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Chantal",
            "LanguageCode": "fr-CA",
            "LanguageName": "Canadian French",
            "Name": "Chantal",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Gabrielle",
            "LanguageCode": "fr-CA",
            "LanguageName": "Canadian French",
            "Name": "Gabrielle",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Penelope",
            "LanguageCode": "es-US",
            "LanguageName": "US Spanish",
            "Name": "Penélope",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Miguel",
            "LanguageCode": "es-US",
            "LanguageName": "US Spanish",
            "Name": "Miguel",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Lupe",
            "LanguageCode": "es-US",
            "LanguageName": "US Spanish",
            "Name": "Lupe",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Mia",
            "LanguageCode": "es-MX",
            "LanguageName": "Mexican Spanish",
            "Name": "Mia",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Lucia",
            "LanguageCode": "es-ES",
            "LanguageName": "Castilian Spanish",
            "Name": "Lucia",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Enrique",
            "LanguageCode": "es-ES",
            "LanguageName": "Castilian Spanish",
            "Name": "Enrique",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Conchita",
            "LanguageCode": "es-ES",
            "LanguageName": "Castilian Spanish",
            "Name": "Conchita",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Geraint",
            "LanguageCode": "en-GB-WLS",
            "LanguageName": "Welsh English",
            "Name": "Geraint",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Salli",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Salli",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Matthew",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Matthew",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Kimberly",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Kimberly",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Kendra",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Kendra",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Justin",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Justin",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Joey",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Joey",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Joanna",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Joanna",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Ivy",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Ivy",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Aria",
            "LanguageCode": "en-NZ",
            "LanguageName": "New Zealand English",
            "Name": "Aria",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Ayanda",
            "LanguageCode": "en-ZA",
            "LanguageName": "South African English",
            "Name": "Ayanda",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Raveena",
            "LanguageCode": "en-IN",
            "LanguageName": "Indian English",
            "Name": "Raveena",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Aditi",
            "LanguageCode": "en-IN",
            "LanguageName": "Indian English",
            "Name": "Aditi",
            "AdditionalLanguageCodes": [
                "hi-IN"
            ],
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Emma",
            "LanguageCode": "en-GB",
            "LanguageName": "British English",
            "Name": "Emma",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Brian",
            "LanguageCode": "en-GB",
            "LanguageName": "British English",
            "Name": "Brian",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Amy",
            "LanguageCode": "en-GB",
            "LanguageName": "British English",
            "Name": "Amy",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Russell",
            "LanguageCode": "en-AU",
            "LanguageName": "Australian English",
            "Name": "Russell",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Nicole",
            "LanguageCode": "en-AU",
            "LanguageName": "Australian English",
            "Name": "Nicole",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Olivia",
            "LanguageCode": "en-AU",
            "LanguageName": "Australian English",
            "Name": "Olivia",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Vicki",
            "LanguageCode": "de-DE",
            "LanguageName": "German",
            "Name": "Vicki",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Marlene",
            "LanguageCode": "de-DE",
            "LanguageName": "German",
            "Name": "Marlene",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Hans",
            "LanguageCode": "de-DE",
            "LanguageName": "German",
            "Name": "Hans",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Naja",
            "LanguageCode": "da-DK",
            "LanguageName": "Danish",
            "Name": "Naja",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Mads",
            "LanguageCode": "da-DK",
            "LanguageName": "Danish",
            "Name": "Mads",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Gwyneth",
            "LanguageCode": "cy-GB",
            "LanguageName": "Welsh",
            "Name": "Gwyneth",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Zhiyu",
            "LanguageCode": "cmn-CN",
            "LanguageName": "Chinese Mandarin",
            "Name": "Zhiyu",
            "SupportedEngines": [
                "neural",
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Zeina",
            "LanguageCode": "arb",
            "LanguageName": "Arabic",
            "Name": "Zeina",
            "SupportedEngines": [
                "standard"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Hala",
            "LanguageCode": "ar-AE",
            "LanguageName": "Gulf Arabic",
            "Name": "Hala",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Arlet",
            "LanguageCode": "ca-ES",
            "LanguageName": "Catalan",
            "Name": "Arlet",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Hannah",
            "LanguageCode": "de-AT",
            "LanguageName": "German",
            "Name": "Hannah",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Ruth",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Ruth",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Stephen",
            "LanguageCode": "en-US",
            "LanguageName": "US English",
            "Name": "Stephen",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Kajal",
            "LanguageCode": "en-IN",
            "LanguageName": "Indian English",
            "Name": "Kajal",
            "AdditionalLanguageCodes": [
                "hi-IN"
            ],
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Hiujin",
            "LanguageCode": "yue-CN",
            "LanguageName": "Cantonese",
            "Name": "Hiujin",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Female",
            "Id": "Suvi",
            "LanguageCode": "fi-FI",
            "LanguageName": "Finnish",
            "Name": "Suvi",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Arthur",
            "LanguageCode": "en-GB",
            "LanguageName": "British English",
            "Name": "Arthur",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Daniel",
            "LanguageCode": "de-DE",
            "LanguageName": "German",
            "Name": "Daniel",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Liam",
            "LanguageCode": "fr-CA",
            "LanguageName": "Canadian French",
            "Name": "Liam",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Pedro",
            "LanguageCode": "es-US",
            "LanguageName": "US Spanish",
            "Name": "Pedro",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Sergio",
            "LanguageCode": "es-ES",
            "LanguageName": "Castilian Spanish",
            "Name": "Sergio",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Andres",
            "LanguageCode": "es-MX",
            "LanguageName": "Mexican Spanish",
            "Name": "Andrés",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Remi",
            "LanguageCode": "fr-FR",
            "LanguageName": "French",
            "Name": "Rémi",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Adriano",
            "LanguageCode": "it-IT",
            "LanguageName": "Italian",
            "Name": "Adriano",
            "SupportedEngines": [
                "neural"
            ]
        },
        {
            "Gender": "Male",
            "Id": "Thiago",
            "LanguageCode": "pt-BR",
            "LanguageName": "Brazilian Portuguese",
            "Name": "Thiago",
            "SupportedEngines": [
                "neural"
            ]
        }
    ]
}

Yields:

Gender  Id  LanguageCode    LanguageName    Name    SupportedEngines
Male    Kevin   en-US   US English  Kevin   ["neural"]
Female  Elin    sv-SE   Swedish Elin    ["neural"]
Female  Ines    pt-PT   Portuguese  Inês    ["neural","standard"]
Female  Vitoria pt-BR   Brazilian Portuguese    Vitória ["neural","standard"]
Female  Camila  pt-BR   Brazilian Portuguese    Camila  ["neural","standard"]
Female  Ola pl-PL   Polish  Ola ["neural"]
Female  Laura   nl-NL   Dutch   Laura   ["neural"]
Female  Ida nb-NO   Norwegian   Ida ["neural"]
Female  Seoyeon ko-KR   Korean  Seoyeon ["neural","standard"]
Female  Kazuha  ja-JP   Japanese    Kazuha  ["neural"]
Female  Tomoko  ja-JP   Japanese    Tomoko  ["neural"]
Male    Takumi  ja-JP   Japanese    Takumi  ["neural","standard"]
Female  Bianca  it-IT   Italian Bianca  ["neural","standard"]
Female  Lea fr-FR   French  Léa ["neural","standard"]
Female  Gabrielle   fr-CA   Canadian French Gabrielle   ["neural"]
Female  Lupe    es-US   US Spanish  Lupe    ["neural","standard"]
Female  Mia es-MX   Mexican Spanish Mia ["neural","standard"]
Female  Lucia   es-ES   Castilian Spanish   Lucia   ["neural","standard"]
Female  Salli   en-US   US English  Salli   ["neural","standard"]
Male    Matthew en-US   US English  Matthew ["neural","standard"]
Female  Kimberly    en-US   US English  Kimberly    ["neural","standard"]
Female  Kendra  en-US   US English  Kendra  ["neural","standard"]
Male    Justin  en-US   US English  Justin  ["neural","standard"]
Male    Joey    en-US   US English  Joey    ["neural","standard"]
Female  Joanna  en-US   US English  Joanna  ["neural","standard"]
Female  Ivy en-US   US English  Ivy ["neural","standard"]
Female  Aria    en-NZ   New Zealand English Aria    ["neural"]
Female  Ayanda  en-ZA   South African English   Ayanda  ["neural"]
Female  Emma    en-GB   British English Emma    ["neural","standard"]
Male    Brian   en-GB   British English Brian   ["neural","standard"]
Female  Amy en-GB   British English Amy ["neural","standard"]
Female  Olivia  en-AU   Australian English  Olivia  ["neural"]
Female  Vicki   de-DE   German  Vicki   ["neural","standard"]
Female  Zhiyu   cmn-CN  Chinese Mandarin    Zhiyu   ["neural","standard"]
Female  Hala    ar-AE   Gulf Arabic Hala    ["neural"]
Female  Arlet   ca-ES   Catalan Arlet   ["neural"]
Female  Hannah  de-AT   German  Hannah  ["neural"]
Female  Ruth    en-US   US English  Ruth    ["neural"]
Male    Stephen en-US   US English  Stephen ["neural"]
Female  Kajal   en-IN   Indian English  Kajal   ["hi-IN"]   ["neural"]
Female  Hiujin  yue-CN  Cantonese   Hiujin  ["neural"]
Female  Suvi    fi-FI   Finnish Suvi    ["neural"]
Male    Arthur  en-GB   British English Arthur  ["neural"]
Male    Daniel  de-DE   German  Daniel  ["neural"]
Male    Liam    fr-CA   Canadian French Liam    ["neural"]
Male    Pedro   es-US   US Spanish  Pedro   ["neural"]
Male    Sergio  es-ES   Castilian Spanish   Sergio  ["neural"]
Male    Andres  es-MX   Mexican Spanish Andrés  ["neural"]
Male    Remi    fr-FR   French  Rémi    ["neural"]
Male    Adriano it-IT   Italian Adriano ["neural"]
Male    Thiago  pt-BR   Brazilian Portuguese    Thiago  ["neural"]

The first jq command filters the input JSON data to select only the voice objects that have SupportedEngines containing "neural". to_entries converts into an array of key-value pairs.

The resulting array is stored in $e, which is passed to the second jq via a here-file. This "outer" jq first selects the keys of the first object in the array $e, which are guaranteed to be the headers for the TSV output.

Then, it selects the values of each object in $e, converts them to strings using tostring (needed for just one row in our example), and formats them as @tsv.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .