Skip to content

Instantly share code, notes, and snippets.

@gbmele
Forked from HunterGerlach/json-to-csv.awk
Created July 19, 2023 02:06
Show Gist options
  • Save gbmele/56a4001cdbd0f842a237aef2f6a26e97 to your computer and use it in GitHub Desktop.
Save gbmele/56a4001cdbd0f842a237aef2f6a26e97 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