Developers extract GitHub statistics for non-technical stakeholders who work in Excel, marketing needs social media metrics in spreadsheets, and finance requires payment data from APIs in CSV format. This drill teaches you to read nested JSON from provided files (simulating API responses), extract fields from complex structures, flatten to tabular format, and generate CSV output—bridging the API world with the spreadsheet world.
JSON.parse(File.read(file)) parses JSON from file
Access nested values with hash['key']['nested_key']
Date.parse(string).strftime('%Y-%m-%d') formats the date
Build CSV manually: values.join(',')
Use .sum { |r| r['stars'] } to total stars
max_by { |r| r['stars'] } finds the most popular repo
convert_json_to_csv('repos.json')
Converted 3 repositories Total stars: 8,350 Most popular: awesome-ruby (5,000 stars)
csv = convert_json_to_csv('repos.json')
puts csv.lines.first.strip
Converted 3 repositories Total stars: 8,350 Most popular: awesome-ruby (5,000 stars) Name,Description,Owner,Stars,Forks,Language,Open_Issues,Created
csv = convert_json_to_csv('repos.json')
puts csv.lines[1].split(',')[2]
Converted 3 repositories Total stars: 8,350 Most popular: awesome-ruby (5,000 stars) user1
Console output will appear here...
Are you sure?
You're making great progress
Become a Ruby Pro
1,600+ problems to master every concept