Created
July 27, 2022 16:06
-
-
Save thedward/6b7f354c3b3a8d81e4e8cf0b1dd69913 to your computer and use it in GitHub Desktop.
Simple csvtojson script with jq
This file contains hidden or 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
#!/usr/bin/env -S jq -Rnf | |
def csvarray:split(",")|map(fromjson); | |
def objectify($ks): [$ks,(.|csvarray)]|[transpose[] as [$key,$value]|{$key,$value}]|from_entries; | |
(input|csvarray) as $keys|[inputs|objectify($keys)|.csv_filename=input_filename] | |
| reduce .[] as $o ({}; .[$o.csv_filename]+=[($o|del(.csv_filename))]) | |
| if length == 1 and has("<stdin>") then ."<stdin>" else . end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment