Developer Workflow
Convert CSV to JSON for spreadsheet data cleanup
Learn how to convert spreadsheet CSV exports into JSON while checking headers, delimiters, empty cells, and nested-looking values.
Problem
CSV exports are easy to move between spreadsheets, but APIs and test fixtures usually expect JSON. Problems appear when headers are missing, delimiters differ, or empty cells need consistent handling.
When to use this
- A spreadsheet export needs to be pasted into an API request.
- A product or customer list needs to become a JSON fixture.
- A CSV file should be checked before importing it into an internal tool.
Steps
- Step 1
Check the header row
Make sure the first row contains stable field names that can become JSON keys.
- Step 2
Convert CSV to JSON
Paste the CSV and convert it into an array of objects so each row becomes a structured record.
- Step 3
Inspect empty and numeric-looking fields
Decide whether empty cells should stay empty strings, null values, or be removed before importing.
- Step 4
Format the JSON result
Pretty-print the JSON output before using it in tests, examples, or API debugging.
Example
CSV rows converted to JSON objects
Input
id,email,plan
42,dev@example.com,pro
43,ops@example.com,starterOutput
[
{
"id": "42",
"email": "dev@example.com",
"plan": "pro"
},
{
"id": "43",
"email": "ops@example.com",
"plan": "starter"
}
]Common mistakes
Using human labels as API keys
Rename headers like Customer Email to stable keys such as customerEmail or email before generating fixtures.
Ignoring commas inside quoted cells
Addresses, names, and descriptions may include commas. A converter should respect quoted CSV cells instead of splitting blindly.
FAQ
Should CSV numbers become JSON numbers?
It depends on the API. IDs, postal codes, and account numbers are often safer as strings because leading zeros can matter.
What if my CSV uses semicolons?
Some spreadsheet exports use semicolons based on locale settings. Pick the delimiter that matches the file before converting.
Can CSV represent nested JSON?
CSV is flat by default. Nested JSON usually requires a mapping rule or a later transform after the basic conversion.