Re:CSV Challenge
by th0br0 on Saturday April 25, 2015 @10:31AM
(#9438400)
You forgot the select(.creditcard) - see my comment on the gist - as this one does not filter out null'ed creditcards:
[ Parent
| on HN ]
If we're going for succinctness, you could combine these all together:
(echo '"Name","Credit Card"'; jq -r '.[] | select(.creditcard) | [.name, .creditcard] | @csv' data.json) >> `date +%Y%m%d`.csv
Re:CSV Challenge
by vitorbaptistaa on Saturday April 25, 2015 @10:47AM
(#9438439)
Nice trick to write the headers, thanks!
I used jq as well, though instead of doing a seperate echo I did this:
([{name: "name", creditcard: "creditcard"}] + .)[]
instead of .[]Another less hacky way would be:
[["name", "creditcard"]] + map(select(.creditcard) | [.name, .creditcard]) | .[] | @csv
Re:CSV Challenge
by vitorbaptistaa on Saturday April 25, 2015 @10:39AM
(#9438419)
You're right! I missed that requirement.