How to Convert JSON to CSV (Online, Python, and More)

Convert JSON to CSV for Excel, Google Sheets, or data pipelines. Covers online tools, Python code, nested JSON handling, and common conversion issues.

BY ALI HASSAN·

How to Convert JSON to CSV

JSON is the default format for APIs and modern data storage. CSV is what most humans want when they open data — Excel, Google Sheets, and most BI tools read it directly. Converting between the two is a daily task for developers and data analysts.

Mizakii's JSON to CSV converter handles it in one paste — no code, no setup.

How JSON to CSV Conversion Works

CSV is a flat format: rows and columns. JSON can be deeply nested. The conversion only works cleanly when the JSON is an array of objects with consistent keys.

Ideal input (array of objects)

[
  { "name": "Ali Hassan", "email": "ali@example.com", "plan": "pro" },
  { "name": "Jane Doe", "email": "jane@example.com", "plan": "free" },
  { "name": "Bob Smith", "email": "bob@example.com", "plan": "pro" }
]

This maps directly to CSV:

name,email,plan
Ali Hassan,ali@example.com,pro
Jane Doe,jane@example.com,free
Bob Smith,bob@example.com,pro

The keys from the first object become headers. Each object becomes a row.


Common Issues and How to Handle Them

Missing keys in some objects

[
  { "name": "Ali", "email": "ali@example.com", "plan": "pro" },
  { "name": "Jane", "email": "jane@example.com" }
]

Jane has no plan key. Most converters leave the cell empty in that column — which is correct behaviour. The column still appears; the value is just blank.

Nested objects

[
  {
    "name": "Ali",
    "address": { "city": "London", "country": "UK" }
  }
]

Nested objects don't map cleanly to CSV columns. Common solutions:

  • Flatten: create columns address.city and address.country
  • Stringify: put the JSON string of the nested object in a single cell
  • Ignore: drop the nested key entirely

For most reporting use cases, flattening is the most useful option.

Arrays inside objects

[
  { "name": "Ali", "tags": ["developer", "designer"] }
]

Arrays inside objects are even harder to map to CSV — how many columns do you allocate for tags? Common approaches:

  • Join to a single string: "developer,designer" in one cell
  • Take only the first value
  • Drop the key

JSON wrapped in a top-level object

APIs often return:

{
  "data": [
    { "name": "Ali", "email": "ali@example.com" }
  ],
  "total": 1
}

You need to extract the inner array first. Either edit the JSON to pull out the data array before converting, or use a tool that accepts a JMESPath or dot-notation selector.


Convert JSON to CSV in Python

For repeatable conversions, a few lines of Python using the standard library:

import json
import csv

with open('data.json', 'r') as f:
    data = json.load(f)

# data should be a list of dicts
keys = data[0].keys()

with open('output.csv', 'w', newline='') as f:
    writer = csv.DictWriter(f, fieldnames=keys)
    writer.writeheader()
    writer.writerows(data)

print("Done. output.csv created.")

For nested JSON, use pandas:

import pandas as pd
import json

with open('data.json') as f:
    data = json.load(f)

df = pd.json_normalize(data)  # flattens nested objects with dot notation
df.to_csv('output.csv', index=False)

pd.json_normalize handles one level of nesting automatically. For deeper nesting, pass max_level=2 or similar.


When to Use an Online Tool vs Code

| Situation | Best approach | |-----------|--------------| | One-off conversion, simple flat JSON | Online tool | | Repeated conversion (daily/weekly) | Python/Node.js script | | CI/CD pipeline | Code (scripted) | | Large files (100MB+) | Code (streaming) | | Complex nested JSON needing custom logic | Code | | Non-technical user needs the output | Online tool |

For quick, one-off conversions where you just need the CSV to paste into a spreadsheet, an online converter is faster than writing and running a script.


Convert JSON to CSV in Node.js

If you prefer JavaScript or are working in a Node.js pipeline:

const fs = require('fs');

const data = JSON.parse(fs.readFileSync('data.json', 'utf8'));

// Get all unique keys across all objects
const headers = [...new Set(data.flatMap(obj => Object.keys(obj)))];

const csvRows = [
  headers.join(','),
  ...data.map(row =>
    headers.map(header => {
      const val = row[header] ?? '';
      // Wrap in quotes if the value contains a comma, quote, or newline
      const escaped = String(val).replace(/"/g, '""');
      return /[,"\n]/.test(escaped) ? `"${escaped}"` : escaped;
    }).join(',')
  )
];

fs.writeFileSync('output.csv', csvRows.join('\n'));
console.log('Done. output.csv written.');

This handles missing keys (fills blank) and properly escapes values that contain commas or quotes.


Handling Special Characters in CSV

CSV has a few tricky cases that break naive converters:

Values containing commas — the value must be wrapped in double quotes: "London, UK". If your converter doesn't do this, the comma splits into an extra column.

Values containing double quotes — the quote must be escaped by doubling it: "He said ""hello""". A value of He said "hello" becomes "He said ""hello""" in CSV.

Values containing newlines — rare but possible in addresses or multi-line text fields. Must also be wrapped in quotes.

Unicode and non-ASCII characters — CSV has no encoding standard, but UTF-8 is the modern default. If your CSV opens in Excel and shows garbled characters, save with UTF-8 BOM (Excel requires the BOM to detect UTF-8).


Importing the CSV into Excel and Google Sheets

Google Sheets — File → Import → Upload → choose your CSV. Set delimiter to comma. Data imports cleanly.

Excel — double-clicking a CSV usually opens it, but if characters look wrong: Data tab → From Text/CSV → choose your file → set encoding to UTF-8. Don't double-click UTF-8 CSV files with special characters — Excel defaults to a legacy encoding.

Large files — Excel has a 1,048,576 row limit. Google Sheets has a 10 million cell limit. For larger datasets, use a proper database or BI tool (DuckDB, Pandas, Tableau).


Convert JSON to CSV Now

Open Mizakii JSON to CSV →

Paste your JSON array, get a CSV instantly. Copy to clipboard or download the file. Free, no signup, runs in your browser.