Convert JSON to CSV

  • install jq (https://github.com/jqlang/jq/releases)
#!/bin/bash

# Check if the input file is provided
if [ "$#" -ne 2 ]; then
    echo "Usage: $0 input.json output.csv"
    exit 1
fi

# Convert JSON to CSV
jq -r '(.[] | [."name", ."age", ."city"] | @csv)' "$1" > "$2"
  • https://github.com/jqlang/jq
  • https://jqlang.org/
  • https://bashscript.net/bash-script-to-convert-json-to-csv/
  • https://www.baeldung.com/linux/jq-command-json
  • https://www.digitalocean.com/community/tutorials/how-to-transform-json-data-with-jq
Feedback