4 ms·
Perl (assuming the data is downloaded): perl -0777 -MJSON -le ' print for "name,creditcard\n", map {"$_->{name},$_->{creditcard}\
by prakashk 11y ago
Perl (assuming the data is downloaded):
perl -0777 -MJSON -le '
print for "name,creditcard\n",
map {"$_->{name},$_->{creditcard}\n"}
grep {$_->{creditcard}}
@{JSON->new->decode(<>)}
' data.json > 20150425.csv
- jakejake 11y agoIt's been years since I wrote perl. Any kind soul care to comment some of this code? It looks like the logic starts at the bottom, but I must admit defeat in truly understanding how it works!
- a1369209993 11y agodecode input from JSON grep for items with a 'creditcard' field map each item to a string with its 'name' and 'creditcard' fields for each string (and "name,creditcard\n"), print it into 20150425.csv
- hawkice 11y agoPerl is water in the cupped hands of our minds. I have yet to meet someone who can keep it from slipping between their fingers without consistent effort.
- vram22 11y agoInnovative analogy.
- prakashk 11y agoIn addition to the explanation by a1369209993's explanation (https://news.ycombinator.com/item?id=9438730 https://news.ycombinator.com/item?id=9438730): * <> reads from file(s) specified as command-line arguments (data.json in this case) * Option -0777 tells Perl to slurp the whole file * Option -MJSON loads the JSON module