require "json" require "open-uri" url = "https://gist.githubusercontent.com/jorinvo/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json" data = JSON.parse(open(url).read) filtered_data = data.select { |line| not line["creditcard"].nil? } file = File.open(DateTime.now.strftime("%Y%m%d") + ".csv", 'w') file.write "Name,Creditcart\n" filtered_data.each do |line| file.write [line["name"], line["creditcard"]].join(',') file.write("\n") end
Or if you guys line nasty oneliners (requre statements don't count)
require "json" require "open-uri" File.open(DateTime.now.strftime("%Y%m%d") + ".csv", 'w') { |file| file.write "Name,Creditcard\n"; JSON.parse(open("https://gist.githubusercontent.com/jorinvo/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json").read).select { |line| not line["creditcard"].nil? }.each { |line| file.write "#{line['name']},#{line['creditcard']}\n" } }
I'm trying to do it in Elixir now :D
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Or if you guys line nasty oneliners (requre statements don't count)
I'm trying to do it in Elixir now :D