Skip to content

Instantly share code, notes, and snippets.

@HunterGerlach
Created June 22, 2022 15:57
Show Gist options
  • Save HunterGerlach/98f4b75fe1fe8f8cf5169e08c39e53bf to your computer and use it in GitHub Desktop.
Save HunterGerlach/98f4b75fe1fe8f8cf5169e08c39e53bf to your computer and use it in GitHub Desktop.
How to convert a JSON file to CSV with AWK
# Usage: awk -f json-to-csv.awk values.json > output.csv
# Note: You may encounter issues w/ esacping values or missing/empty fields
BEGIN{ OFS=""; u=f=l=a=e=""; }
/"username"/{ u=$2 }
/"first_name"/{ f=$2 }
/"last_name"/{ l=$2 }
/"asset_type"/{ a=$2 }
/"email"/{ e=$2 }
{ if(e!="") { print u,f,l,a,e; e="" }} # add for any potentially empty lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment