Challenge

Problem

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.

Difficulty: Intermediate

Instructions

  1. Read JSON file containing array of GitHub repository objects
  2. Extract fields from nested structures:
    • Repository name, description, stars, forks
    • Owner name (nested in owner object)
    • Created date (parse and format as YYYY-MM-DD)
    • Language, open issues count
  3. Flatten nested data to tabular format
  4. Generate CSV string with headers
  5. Output summary: Total repos: X, Total stars: Y, Most popular: Z
  6. Return the CSV string

Files

Editable
Read-only

Hints

Hint 1

JSON.parse(File.read(file)) parses JSON from file

Hint 2

Access nested values with hash['key']['nested_key']

Hint 3

Date.parse(string).strftime('%Y-%m-%d') formats the date

Hint 4

Build CSV manually: values.join(',')

Hint 5

Use .sum { |r| r['stars'] } to total stars

Hint 6

max_by { |r| r['stars'] } finds the most popular repo

Ruby 3.4

Provided Files (Read-only)

1. Correct summary output

Input:
convert_json_to_csv('repos.json')
Expected Output:
Converted 3 repositories
Total stars: 8,350
Most popular: awesome-ruby (5,000 stars)

2. CSV has correct headers

Input:
csv = convert_json_to_csv('repos.json')
puts csv.lines.first.strip
Expected Output:
Converted 3 repositories
Total stars: 8,350
Most popular: awesome-ruby (5,000 stars)
Name,Description,Owner,Stars,Forks,Language,Open_Issues,Created

3. Extracts nested owner

Input:
csv = convert_json_to_csv('repos.json')
puts csv.lines[1].split(',')[2]
Expected Output:
Converted 3 repositories
Total stars: 8,350
Most popular: awesome-ruby (5,000 stars)
user1
+ 2 hidden test cases