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 export to CSV—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. Calculate additional metrics (stars per day since creation)
  5. Write to CSV with headers
  6. Output summary: Total repos: X, Total stars: Y, Most popular: Z

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) converts ISO 8601 dates

Hint 4

Calculate days: (Date.today - date).to_i

Hint 5

Use .dig for safe nested access: hash.dig('owner', 'login')

Hint 6

Map array to transform each element: array.map { |item| ... }

Hint 7

CSV writes arrays as rows automatically

Provided Files (Read-only)

1. Basic JSON to CSV - 2 repos

Input:
convert_json_to_csv('repos.json')
Expected Output:
Converted 2 repositories
Total stars: 3,000
Most popular: rails-app (2,000 stars)

2. Single repository

Input:
convert_json_to_csv('repos.json')
Expected Output:
Converted 1 repository
Total stars: 500
Most popular: solo-repo (500 stars)

3. Multiple repos with varying stars

Input:
convert_json_to_csv('repos.json')
Expected Output:
Converted 3 repositories
Total stars: 5,400
Most popular: repo-b (5,000 stars)
+ 2 hidden test cases