Developer Workflow
Fix CSV and JSON conversion errors
Diagnose CSV to JSON and JSON to CSV conversion problems caused by headers, quoted commas, delimiters, empty cells, encoding, and malformed JSON.
Problem
CSV and JSON conversion failures usually come from structure mismatches rather than the converter itself. Header rows, quoted delimiters, blank values, byte order marks, multiline cells, and malformed JSON can all produce output that looks valid in a quick preview but imports incorrectly into a spreadsheet, database, or API test.
When to use this
- A CSV export creates shifted columns or missing JSON keys after conversion.
- A JSON payload will not convert to CSV because the structure is invalid or inconsistent.
- Names, addresses, or descriptions contain commas that split into extra cells.
- Imported text shows replacement characters, odd accents, or a hidden BOM before the first header.
- A spreadsheet import rejects the converted file because blank cells, nested fields, or inconsistent columns were handled unexpectedly.
Steps
- Step 1
Check the header row first
Confirm the first CSV row contains stable field names. Empty, duplicate, or human-only labels should be fixed before generating JSON objects.
- Step 2
Verify delimiters and quoted cells
Look for commas inside names, addresses, and descriptions. Values containing delimiters should be quoted so columns do not shift during parsing.
- Step 3
Format JSON before converting back to CSV
When starting from JSON, run the payload through JSON Formatter so syntax errors and inconsistent record shapes are visible before export.
- Step 4
Check encoding when characters look wrong
If headers or values contain broken characters, inspect the text encoding and remove hidden BOM characters before retrying the conversion.
- Step 5
Test a small round trip
Convert a few representative rows first, then reopen the result in the target spreadsheet, API client, or data pipeline before processing the full file.
Example
Quoted commas keep CSV columns aligned
Input
id,name,note
1,Ada,"uses commas, safely"
2,Linus,"exports cleanly"Output
[{"id":"1","name":"Ada","note":"uses commas, safely"},{"id":"2","name":"Linus","note":"exports cleanly"}]Common mistakes
Leaving duplicate headers in the CSV
Duplicate column names can overwrite values or create confusing keys. Rename duplicated headers before converting rows into JSON objects.
Changing delimiters without checking the file
Locale-specific exports may use semicolons, but many files still use commas. Match the delimiter to the actual file instead of guessing.
Treating encoding problems as data loss
Broken characters often mean the file was decoded with the wrong charset or includes a BOM. Check encoding before editing every affected value manually.
Flattening nested JSON without choosing columns
Nested API responses may contain objects or arrays inside each record. Decide which nested fields should become CSV columns before exporting, otherwise cells can turn into unreadable serialized blobs.
Forgetting multiline CSV cells
Addresses, comments, and descriptions can contain line breaks inside quoted cells. Treat those line breaks as part of the value instead of starting a new record.
FAQ
Why did my CSV columns shift after conversion?
A comma, newline, or delimiter inside a value was probably not quoted correctly. Check the row where columns start shifting and quote the affected cell.
Why does JSON to CSV fail on my API response?
The converter expects a consistent array of records. Format the JSON first, then extract the array you want if the response is wrapped in metadata.
How do I fix strange characters in CSV headers?
Check the file encoding and hidden byte order mark before changing the data. Encoding issues can make the first header or non-English text appear corrupted.
What should I do when JSON records have different keys?
Normalize the record shape before exporting to CSV. Add missing keys intentionally, rename conflicting fields, and choose a stable column order so spreadsheet imports do not move values into the wrong headers.
Should blank CSV cells become empty strings or missing fields?
Pick the representation that matches the destination system. Empty strings preserve table shape for spreadsheets, while omitted fields can be better for APIs that treat absent values differently from blank text.
How do I handle newlines inside CSV values?
Keep multiline values inside quoted cells and verify the row count after conversion. A line break inside a quoted value should not create a new record.