简体   繁体   中英

Using jq to extract values and format in CSV

I have the below json file:

{
"data": [
    {
        "displayName": "First Name",
        "rank": 1,
        "value": "VALUE"
    },
    {
        "displayName": "Last Name",
        "rank": 2,
        "value": "VALUE"
    },
    {
        "displayName": "Position",
        "rank": 3,
        "value": "VALUE"
    },
    {
        "displayName": "Company Name",
        "rank": 4,
        "value": "VALUE"
    },
    {
        "displayName": "Country",
        "rank": 5,
        "value": "VALUE"
    },
]
}

I would like to have a CSV file in this format:

First Name, Last Name, Position, Company Name, Country

VALUE, VALUE, VALUE, VALUE, VALUE, VALUE

Is this possible by using only jq? I don't have any programming and/or great command-line skills.

当然是啦:

.data | sort_by(.rank) | map(.displayName), map(.value) | @csv

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