← Home · Blog

How to Convert JSON to CSV for Excel

Published: May 23, 2025 · 5 min read

You have JSON data from an API and need to open it in Excel or Google Sheets. JSON's nested structure doesn't directly translate to rows and columns — so you need a conversion step. This guide shows you exactly how to do it.

What You Need

For JSON to CSV conversion to work, your JSON should be an array of objects where each object represents a row:

[ {"name": "Alice", "age": 30, "city": "New York"}, {"name": "Bob", "age": 25, "city": "London"}, {"name": "Charlie", "age": 35, "city": "Tokyo"} ]

This converts cleanly to a table with 3 rows and 3 columns (name, age, city).

Method 1: Online Tool (Fastest)

The quickest approach for any size of data:

  1. Go to JSON ↔ CSV Converter
  2. Paste your JSON array in the input editor
  3. Click "Convert to CSV"
  4. Preview the table to verify correctness
  5. Click "Download CSV" — open directly in Excel

The tool handles edge cases automatically: commas in values get properly quoted, nested objects get flattened, and null values become empty cells.

Method 2: JavaScript Code

If you need to convert programmatically:

function jsonToCsv(jsonArray) { const headers = Object.keys(jsonArray[0]); const csvRows = [headers.join(',')]; for (const row of jsonArray) { const values = headers.map(h => { const val = String(row[h] ?? ''); // Escape commas and quotes return val.includes(',') || val.includes('"') ? `"${val.replace(/"/g, '""')}"` : val; }); csvRows.push(values.join(',')); } return csvRows.join('\n'); }

Method 3: Python

import json, csv, io data = json.loads('[{"name":"Alice","age":30}]') output = io.StringIO() writer = csv.DictWriter(output, fieldnames=data[0].keys()) writer.writeheader() writer.writerows(data) print(output.getvalue())

Handling Nested Objects

Real-world JSON often has nested structures:

[{"name": "Alice", "address": {"city": "NYC", "zip": "10001"}}]

You can't put an object into a single CSV cell. The solution is flattening — converting nested keys to dot notation:

name,address.city,address.zip Alice,NYC,10001

Our JSON to CSV tool does this flattening automatically. Each nested key becomes a separate column with a dotted path name.

Handling Arrays Inside Objects

If a field contains an array (e.g., "tags": ["dev", "admin"]), it gets serialized as a JSON string in the CSV cell: "[""dev"",""admin""]". This preserves the data but isn't ideal for spreadsheet analysis. Consider extracting arrays into separate columns or rows depending on your needs.

Tips for Clean Conversion

  • Ensure all objects in your array have the same keys — inconsistent keys may cause empty columns
  • Remove null or undefined values before converting if you want clean spreadsheets
  • For large datasets (10,000+ rows), convert in chunks to avoid browser memory issues
  • If you need Excel format (.xlsx) directly, use our JSON to Excel converter instead
  • For bulk conversion of multiple files, try Bulk Convert

CSV to JSON (Reverse)

Need to go the other direction? Our tool also converts CSV back to JSON. The first row becomes the property names, and each subsequent row becomes a JSON object. This is useful when importing spreadsheet data into a web application or API.

More Articles

What is JSON — A Simple Explanation

How to Format JSON — Beginner's Guide

JSON API Best Practices

← All Articles · Home · About · Privacy Policy