How can I convert my JSON to CSV using jq?

前端 未结 5 1658
礼貌的吻别
礼貌的吻别 2020-12-28 17:25

I have the following JSON data:

{\"id\":\"111\",\"case\":\"Y\",\"custom\":{\"speech invoked\":\"no\",\"input method\":\"hard\",\"session ID\":\"420\"}}
         


        
5条回答
  •  灰色年华
    2020-12-28 17:56

    Using jq, you can use this filter:

    with_entries(select(.key != "custom")) + .custom
        | to_entries
        | map(.key), map(.value)
        | @csv
    

    Just note that written this way, the "custom" properties will always be written in the end, no matter what order the properties are in.

提交回复
热议问题