How to convert JSON to CSV using Linux / Unix shell

www.laut‮ut‬ri.com
How to convert JSON to CSV using Linux / Unix shell

To convert a JSON file to CSV using the Linux or Unix shell, you can use the jq command-line tool. Here is an example of how to do this:

  1. Install jq by running the following command:
sudo apt-get install jq
  1. Convert the JSON file to CSV using the following command:
jq -r '. | keys[] as $k | "\($k),\(.[$k])"' input.json > output.csv

Replace input.json with the name of your JSON file and output.csv with the name you want to give to the resulting CSV file.

This command will extract the keys from the JSON object and use them as the column headers in the CSV file. The values will be placed in the corresponding rows.

Created Time:2017-10-28 21:39:00  Author:lautturi