Use jq to Convert json File to csv

前端 未结 1 1773
暖寄归人
暖寄归人 2021-01-25 08:45

I am using curl to pull Alien Vault OTX pulses from their API, the initial output I receive is in json format and I need to convert this json into csv as so it can be read by so

1条回答
  •  孤街浪徒
    2021-01-25 09:11

    .results is an array so you'll have to expand it too. This can be done either by:

     .results[] | .indicators[] | [.indicator, .type] | @csv
    

    or more compactly:

     .results[].indicators[] | [.indicator, .type] | @csv
    

    You'll also have to direct the output to the designated file, e.g.:

      jq -r -f program.jq < AV.json > AV.csv
    

    Output

    "CVE-2018-0802","CVE"
    "fb9c9cbf6925de8c7b6ce8e7a8d5290e628be0b82a58f3e968426c0f734f38f6","FileHash-SHA256"
    

    0 讨论(0)
提交回复
热议问题