Lesson 4

CSV to JSON for API Fixtures

Turn spreadsheet samples into JSON objects for mocks, tests, and docs.

CSV is often how sample data arrives. JSON is often how developers need to use it.

For API mocks, tests, and documentation, a header row usually maps well to JSON object keys:

id,name,active
1,Ada,true
[
  {
    "id": 1,
    "name": "Ada",
    "active": true
  }
]

Type inference is a choice

Turning "1" into 1 and "true" into true can be useful for fixtures. But it can be dangerous for:

  • Account IDs with leading zeros
  • ZIP or postal codes
  • Large numeric identifiers
  • Codes that look like numbers but are really strings

Disable type inference when exact text matters.

API fixture checklist

  • Use stable header names that match the API contract.
  • Keep row counts small for unit tests.
  • Preserve strings when IDs or codes need exact formatting.
  • Validate the final JSON with a formatter or schema when the payload matters.

Key takeaway

CSV → JSON is not just a format change. It is a schema decision: keys, types, nulls, and arrays should match the target API.

Use the CSV Converter with type inference on and off to compare fixture output.

When you want to practice, use the related DevCove tool — optional, not part of this lesson.

Open related tool

Back to course overview