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, and malformed JSON can all produce output that looks valid but imports incorrectly.

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.

Steps

  1. 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.

  2. 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.

  3. 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.

  4. 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.

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.

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.