jsoncsvconverterexceltutorial

JSON to CSV — How to Convert JSON Arrays to Spreadsheets

·8 min read·Converters

Why Convert JSON to CSV?

JSON is the standard format for APIs and web applications. CSV is the standard format for spreadsheets, databases, and data analysis tools like Excel, Google Sheets, and Pandas. Converting between them lets you take live API data into the tools analysts and stakeholders already use — without writing code every time.

Common scenarios: exporting a user list from an API into a spreadsheet for a client, feeding API data into a data pipeline that requires CSV, or importing records into a legacy system that only accepts flat files.

What JSON Structure Works Best for CSV?

CSV conversion works best with a JSON array of uniformly shaped objects. Each object becomes one row and each key becomes a column header.

json
[
  { "id": 1, "name": "Ravi",  "city": "Surat",     "age": 28, "active": true },
  { "id": 2, "name": "Priya", "city": "Ahmedabad", "age": 24, "active": false },
  { "id": 3, "name": "Arjun", "city": "Vadodara",  "age": 31, "active": true }
]

Result:

id,name,city,age,active
1,Ravi,Surat,28,true
2,Priya,Ahmedabad,24,false
3,Arjun,Vadodara,31,true

Arrays of primitives (e.g., [1, 2, 3]) do not map well to CSV because there are no column names.

Handling Nested Objects with Dot Notation

Real API responses often have nested objects. JSONKit automatically flattens them using dot-notation column names:

json
[{
  "name": "Ravi",
  "address": {
    "street": "MG Road",
    "city": "Surat",
    "pincode": "395007"
  },
  "score": 98.5
}]

Flattened CSV:

name,address.street,address.city,address.pincode,score
Ravi,MG Road,Surat,395007,98.5

Each nested key path becomes a column name. This makes deeply nested API payloads readable in a spreadsheet without any manual transformation.

Handling Arrays Inside Objects

Arrays inside objects are serialized as JSON strings in the CSV cell — they cannot be naturally represented in flat CSV format:

json
[{ "name": "Ravi", "tags": ["admin", "editor"] }]

Result:

name,tags
Ravi,"[""admin"",""editor""]"

The double quotes around the array value and the escaped inner quotes follow RFC 4180 CSV rules. If you need to analyze the array values in Excel, you will need to split them in a separate step.

Choosing a Delimiter

DelimiterWhen to use
Comma (,)Default; works everywhere in English-locale systems
Semicolon (;)Standard in European countries where comma is the decimal separator
TabTSV — best when values contain commas
Pipe ()When values contain both commas and tabs

JSONKit's JSON to CSV converter lets you switch delimiters instantly in the output toolbar without re-pasting your JSON.

Inconsistent Keys Across Objects

Real-world JSON arrays sometimes have objects with different sets of keys. The converter collects all unique keys seen across every object and uses them as column headers. Missing values become empty cells:

json
[
  { "name": "Ravi",  "phone": "9876543210" },
  { "name": "Priya", "email": "priya@example.com" }
]

Output:

name,phone,email
Ravi,9876543210,
Priya,,priya@example.com

Opening CSV in Excel

  1. Open Excel and go to File → Import (do NOT double-click the CSV — that uses the system locale for delimiter detection)
  2. Choose "From Text/CSV"
  3. Set encoding to UTF-8
  4. Set the delimiter to match your file

In Google Sheets: File → Import → Upload → select the file → Google Sheets auto-detects delimiter and encoding.

Converting JSON to CSV in Code

JavaScript (Node.js):

javascript
function jsonToCSV(arr) {
  if (!arr.length) return "";
  const headers = Object.keys(arr[0]);
  const rows = arr.map(obj =>
    headers.map(h => {
      const val = obj[h] ?? "";
      const str = typeof val === "object" ? JSON.stringify(val) : String(val);
      return str.includes(",") ? `"${str.replace(/"/g, '""')}"` : str;
    }).join(",")
  );
  return [headers.join(","), ...rows].join("\n");
}

const fs = require("fs");
const data = JSON.parse(fs.readFileSync("data.json", "utf8"));
fs.writeFileSync("output.csv", jsonToCSV(data));

Python with pandas:

python
import pandas as pd

df = pd.read_json("data.json")
df.to_csv("output.csv", index=False, encoding="utf-8")
print(df.head())

Python without pandas (stdlib only):

python
import json, csv

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

with open("output.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.DictWriter(f, fieldnames=data[0].keys())
    writer.writeheader()
    writer.writerows(data)

Live Table Preview in JSONKit

JSONKit's JSON to CSV tool shows a live table preview with sticky column headers and alternating row colors as you type — verify the output before downloading. The stats bar shows row count, column count, and file size.

Try JSON to CSV

Convert JSON arrays to CSV for Excel or Google Sheets, instantly.