Document 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.
Written and tested by SimpleWebUtilsPublished: Reviewed:
How this workflow was checked
The CSV to JSON and JSON to CSV Converter check used the exact input from “Quoted commas keep CSV columns aligned”. After “Check the header row first” and “Format JSON before converting back to CSV”, we matched the resulting values or file against the documented output and inspected the risks described by “Changing delimiters without checking the file” and “Treating encoding problems as data loss”.
The quoted comma remained inside Ada’s note, both rows retained three fields, and duplicate or uneven headers produced a visible conversion error instead of shifted JSON keys.
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.
Sources and standards
These authoritative references define the formats or security boundaries used in this workflow. Tool-specific verification is documented separately above.
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 headers stop conversion. Duplicate headers are renamed with numbered suffixes and reported, which preserves both values but still requires you to choose meaningful destination keys.
- 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, fix syntax errors first. The converter accepts one object or an array of objects and builds columns from keys found across all rows, so later-row fields are retained as columns instead of being silently dropped.
- Step 4
Choose how nested JSON should become cells
Use flattened paths when nested properties need separate spreadsheet columns, or JSON text when an object or array should stay together in one cell. Review the nested-value warning before downloading.
- Step 5
Check encoding when characters look wrong
A pasted UTF-8 BOM before the first CSV header is removed during conversion. If characters are already broken before pasting, inspect and correct the source encoding first because conversion cannot reconstruct text that was decoded incorrectly.
- Step 6
Test a small round trip
Convert representative rows, download the result, and reopen it in the target spreadsheet, API client, or data pipeline. Check row and column metrics plus every warning 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
The converter prevents silent overwrites by renaming duplicate headers with numbered suffixes and showing a warning. Treat those generated names as a diagnostic, then rename source headers to the meaningful keys expected downstream.
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. Choose flattened field paths for separate columns or JSON text for one-cell values, then inspect a representative row before exporting.
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 root must be one object or an array containing only objects. If an API response wraps records in metadata, extract the record array first. Primitive roots and arrays containing strings, numbers, null, or mixed row types are rejected.
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?
The converter creates a stable union of keys found across all rows and writes missing fields as empty cells with a warning. Review that warning and the complete header row; normalize records first if your destination requires every field to be present.
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.