Lección 4

CSV to JSON for API Fixtures en español

Guía en español para csv csv to json for api fixtures: Turn spreadsheet samples into JSON objects for mocks, tests, and docs.

Este contenido todavía no está disponible en español. Se muestra la versión en English mientras completamos la localización.

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.

Volver al resumen del curso