{
  "id": 15978794,
  "title": "JSON to CSV in Python: the pandas recipe that survives nested data",
  "url": "https://urgent.news/2026/10/22/json-to-csv-in-python-the-pandas-recipe-that-survives-nested-data",
  "topic": "ai",
  "section": "AI",
  "published": "2026-10-22T00:58:34.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/dan_lumatic/json-to-csv-in-python-the-pandas-recipe-that-survives-nested-data-mkm"
  },
  "original_language": "en",
  "account": "The provided recipe demonstrates how to convert JSON data into CSV format using Python's pandas library. Initially, attempting to convert a JSON file resulted in a CSV with unnamed columns and cells containing nested JSON data or Python text representations of objects. The issue lies with the JSON file not being flat, i.e., it is nested.\n\nTo resolve this, the recipe explains various fixes based on the specific error encountered. For an unnamed column issue, setting `index=False` when using `to_csv()` resolves it. When cells contain nested JSON data or Python text, using `json_normalize` with `record_path` and `meta` parameters is recommended. This approach transforms nested values into actual columns.\n\nOther common errors include file not found errors when the JSON file path is provided instead of a file object, trailing data errors when the file is in NDJSON format (one object per line), and KeyError when a required key is missing from a record. Solutions include wrapping the file path in `StringIO()`, setting `errors='ignore'` to ignore missing keys, or building a union of keys.\n\nAdditionally, the recipe highlights differences in CSV formatting between Windows and Unix systems, suggesting to add a `newline=''` parameter when opening the file and using `encoding='utf-8-sig'` to handle files without a byte-order mark. Garbled accents in Excel cells can be fixed by adding the `utf-8-sig` encoding to the `to_csv()` function.\n\nFinally, the recipe advises checking the shape of the JSON data before choosing a method, identifying if the top level is a list of objects, if all objects share the same keys, and if any value is a list or dict. The provided example uses a `orders.json` file, which contains objects with varying levels of nesting. The recipe offers step-by-step instructions on how to apply the fixes to this JSON data and successfully convert it to a CSV file.",
  "summary": "You pasted the five-line recipe and got a CSV with an unnamed 0, 1, 2 column and cells full of {'name': 'Ana', ...} . Or pandas complained about a file you never opened. The recipe is fine. Your JSON just isn't flat. TL;DR Look up your exact error in the table below; six of the eight fixes are a single parameter. Flat array of objects: read_json plus to_csv(index=False) . Nested: json_normalize…",
  "key_points": [
    "JSON data in article is nested, causing issues in CSV conversion",
    "pandas library and jsonnormalize method fix unnamed columns and nested data",
    "Recipe covers file errors, encoding issues, and system formatting differences"
  ],
  "editors_take": "Using jsonnormalize transforms complex nested structures into flat columns, allowing developers to bypass the common pitfalls of unnamed columns and unreadable text representations during data conversion.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}