Created
August 1, 2014 09:52
-
-
Save mikkun/2e120224c47476f98a41 to your computer and use it in GitHub Desktop.
One-Liner: Convert CSV to JSON with header row as key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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