Skip to content

Instantly share code, notes, and snippets.

@mikkun
Created August 1, 2014 09:52
Show Gist options
  • Save mikkun/2e120224c47476f98a41 to your computer and use it in GitHub Desktop.
Save mikkun/2e120224c47476f98a41 to your computer and use it in GitHub Desktop.
One-Liner: Convert CSV to JSON with header row as key
cat input.csv | awk 'BEGIN{FS=","}NR==1{print "[";n=split($0,k)}NR>=2{for(i=1;i<=n;i++){r=r"\""k[i]"\":\""$i"\", "}{sub(/, $/,"",r);print " {"r"},";r=""}}' | sed '$s/,$/\n]/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment