Error Handling Debugging JSON CSV

5 Common JSON to CSV Conversion Errors and How to Fix Them

Published: July 2, 2026 · 10 min read · Keywords: json to csv error handling, fix malformed json

1 Malformed JSON — Unexpected Token

This is the #1 most common error. Your JSON has syntax issues that prevent parsing. The converter throws an error like:

Error: Unexpected token ' in JSON at position 42

Common Causes

❌ Wrong — Single Quotes

{
  'name': 'Alice'
}

✅ Correct — Double Quotes

{
  "name": "Alice"
}
  • Single quotes instead of double quotes — JSON requires " (double quotes) for all strings and keys
  • Trailing commas{"a": 1,} is invalid (remove the last comma)
  • Unescaped characters — Newlines or quotes inside strings must be escaped: \n, \"
  • Comments in JSON — Standard JSON does not support // comments

🛠 How to Fix

  • Use a JSON validator like JSONLint to find the exact error location
  • In VS Code, format the file with Shift+Alt+F to auto-detect issues
  • Use JSON.parse() in browser console for quick validation

Quick Validation Script

// Paste this in browser DevTools console
try {
    JSON.parse(yourJsonString);
    console.log("✅ Valid JSON!");
} catch (e) {
    console.error("❌ Error:", e.message);
}

2 Encoding Issues — Garbled Characters

After conversion, your CSV shows å¼ ä¼Ÿ instead of 张伟. This is an encoding mismatch.

Symptom: Chinese, Japanese, Arabic, or emoji characters appear as gibberish in Excel.

Root Cause

Excel defaults to the system's local encoding (e.g., GBK on Chinese Windows, Shift-JIS on Japanese Windows) when opening CSV files. If your CSV is UTF-8 without BOM, Excel misinterprets it.

❌ Without BOM

Excel opens CSV with system default encoding → garbled text

✅ With UTF-8 BOM

Excel detects UTF-8 BOM → correct characters displayed

🛠 How to Fix

  • Our converter adds UTF-8 BOM automatically — no action needed
  • In Python: use encoding='utf-8-sig' when writing CSV
  • In Excel: Data → From Text/CSV → set File Origin to "65001: Unicode (UTF-8)"
# Python: Write CSV with BOM for Excel
import csv

with open('output.csv', 'w', newline='', encoding='utf-8-sig') as f:
    writer = csv.writer(f)
    writer.writerows(data)

3 Nested Objects — Data Lost in Conversion

CSV is a flat format. When your JSON has nested structures, data may appear as unreadable strings or get dropped entirely.

Symptom: A column shows [object Object] or the cell contains a JSON string instead of usable data.

Example

// Input JSON
{
  "name": "Alice",
  "address": {
    "city": "NYC",
    "zip": "10001"
  }
}

What Happens

❌ Bad — Naive conversion

nameaddress
Alice[object Object]

✅ Good — Serialized

nameaddress
Alice{"city":"NYC","zip":"10001"}

🛠 How to Fix

  • Our converter automatically serializes nested objects as JSON strings
  • For better Excel experience, flatten the structure first:
    // Flatten nested objects
    function flatten(obj, prefix = '') {
      let result = {};
      for (let key in obj) {
        if (typeof obj[key] === 'object') {
          Object.assign(result, flatten(obj[key], prefix + key + '_'));
        } else {
          result[prefix + key] = obj[key];
        }
      }
      return result;
    }
    // Result: { name: "Alice", address_city: "NYC", address_zip: "10001" }

4 Inconsistent Keys — Missing or Extra Columns

When objects in your JSON array have different keys, some rows may have empty cells or columns may be missing.

Symptom: Some CSV rows have fewer columns than others, or expected columns are missing.

Example

[
  { "name": "Alice", "age": 30, "email": "a@b.com" },
  { "name": "Bob", "age": 25 },
  { "name": "Charlie", "phone": "555-1234" }
]

Result

name age email phone
Alice 30 a@b.com (empty)
Bob 25 (empty) (empty)
Charlie (empty) (empty) 555-1234

🛠 How to Fix

  • Our converter automatically collects all unique keys across all objects and creates columns for each
  • Missing values become empty cells (which is the correct behavior)
  • If you want default values, pre-process the JSON to add missing keys with defaults

5 Large File — Memory Overflow / Timeout

Converting a huge JSON file (100+ MB) can crash your browser or cause timeouts.

Symptom: Browser tab freezes, shows "Aw snap!" or "Out of memory" error.

Why It Happens

  • JSON must be fully loaded into memory before parsing
  • The resulting CSV string doubles the memory usage temporarily
  • Browser tabs typically have a 1–4 GB memory limit

🛠 How to Fix

  • Our converter supports files up to 50 MB — this covers most use cases
  • For larger files, use command-line tools:
    # Using jq (command-line JSON processor)
    cat data.json | jq -r '(.[0] | keys_unsorted) as $keys | $keys, (.[] | [.[$keys[]]]) | @csv' > output.csv

    # Using Python (streaming approach)
    import json, csv, sys

    with open('large.json') as f:
        data = json.load(f)
        headers = list(data[0].keys())
        with open('output.csv', 'w', newline='') as out:
            w = csv.DictWriter(out, headers)
            w.writeheader()
            w.writerows(data)
  • Split large files into chunks: split -l 10000 large.json chunk_

⚠ If your JSON file is over 50 MB, consider using jq or Python for streaming conversion instead of a browser-based tool.

Quick Fix Checklist

Before converting, run through this checklist to avoid common errors:

☑ JSON is valid (validated with JSONLint)

☑ All strings use double quotes ", not single quotes '

☑ No trailing commas in objects or arrays

☑ Special characters are properly escaped (\n, \t, \")

☑ File size is under 50 MB for browser-based conversion

☑ UTF-8 BOM is added for Excel compatibility (our tool does this automatically)

☑ Nested objects are handled (serialized or flattened)

☑ All objects have consistent keys (or you accept empty cells for missing values)

💡 Our JSON to CSV Converter handles all of these automatically — just upload your file and convert!