News for hackers. Stuff that matters.
Re:CSV Challenge by vitorbaptistaa on Saturday April 25, 2015 @10:30AM (#9438398)
Using the excellent jq [1] command

  wget https://gist.githubusercontent.com/jorin-vogel/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json
  echo 'Name,Credit Card' > 20150425.csv
  jq -r '.[] | [.name, .creditcard] | @csv' data.json >> 20150425.csv
This consider that all timestamps are from 2015/04/25 (which is the case with the example dataset, but might not be).

[1] https://stedolan.github.io/jq/

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:

  name=`date +'%Y%m%d'`; 
  echo "name,creditcard" > $name; 
  jq -r '.[] | select(.creditcard) | [.name, .creditcard] | @csv' data.json >> $name
Re:CSV Challenge by nburger on Saturday April 25, 2015 @10:43AM (#9438425)
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!
Re:CSV Challenge by ekimekim on Saturday April 25, 2015 @11:34PM (#9440449)
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.