In this guide
See how a JSON array becomes a table, when CSV is the right format, and how to handle nested values and escaping safely.
You have a JSON array. You need a spreadsheet. Seems simple — until you open Excel and realize it has no idea what JSON is. In this guide, you’ll convert JSON to CSV in seconds — and handle the edge cases that trip most developers up.
Take this JSON:
[
{ "name": "Ada Lovelace", "age": 36, "city": "London" },
{ "name": "Grace Hopper", "age": 85, "city": "New York, NY" },
{ "name": "Katherine Johnson", "age": 101, "city": "White Sulphur Springs" }
]You want a header row and one row per user:
name,age,city
Ada Lovelace,36,London
Grace Hopper,85,"New York, NY"
Katherine Johnson,101,White Sulphur SpringsWhat is JSON to CSV conversion?
JSON (JavaScript Object Notation) is a nested, tree-like format built for APIs and configuration. CSV (Comma-Separated Values) is a flat, tabular format built for spreadsheets and databases.
Converting between them means flattening the tree — turning objects into columns, arrays of records into rows, and property names into headers.
CSV doesn’t have built-in types for nested objects or arrays. Those values need a deliberate representation before they fit into a flat table.
When to convert JSON to CSV
Not every JSON document needs to become CSV. Convert when you need to:
- Open records in Excel, Google Sheets, or another spreadsheet.
- Send a report to a teammate who works with tabular data.
- Import records into a legacy system that accepts CSV.
- Analyze rows in a tool that expects a table as input.
Keep the original JSON when:
- The hierarchy itself is important and flattening would lose meaning.
- Arrays or nested objects must remain structured for another API.
- You need to preserve types or relationships that a flat file cannot express.
Think of CSV as a useful export view of the data, not always a complete replacement for the source.
The manual way (and why it’s painful)
The naive approach is to loop through the array and join each object’s values with commas:
const headers = Object.keys(data[0])
const rows = data.map((obj) =>
Object.values(obj).join(',')
)
const csv = [headers.join(','), ...rows].join('\n')That shortcut works only for very simple data. It breaks as soon as values contain delimiters, quotes, line breaks, or nested types.
Values contain commas
“New York, NY” becomes two columns unless the field is quoted.
Values contain quotes
A quote inside a quoted field must be escaped correctly or a CSV reader may end the field too early.
Nested objects
JavaScript string coercion can turn an object into “[object Object]”, which is not useful data.
Arrays inside objects
Joining values blindly can lose array boundaries or produce ambiguous cells.
Unicode and line breaks
Files should be encoded consistently, and line breaks inside a field must be quoted to keep records intact.
Reliable CSV conversion requires choosing columns, flattening values, escaping fields, and handling empty or inconsistent records.
Converting JSON to CSV with TEO ToolKit
For a quick export, use TEO ToolKit’s JSON to CSV converter. There’s no setup: open the tool, paste a JSON array, and convert.
- 1
Open the JSON to CSV tool
- 2
Paste your JSON array
Use a list of objects with consistent fields for a straightforward table. The sample above is ready to try. - 3
Convert and review the CSV
Check the column order and values, then copy or download the result for your spreadsheet or import workflow.
JSON input
[
{ "name": "Ada",
"city": "London" },
{ "name": "Grace",
"city": "New York, NY" }
]That’s it. Review the output, then copy the CSV, download it as a file, or paste it straight into Google Sheets.
Treat the output as an export and verify important data before importing it into another system, especially when the source contains irregular records.
Handling nested objects
Real JSON is rarely flat. Consider a record with an address object:
[
{
"name": "Ada Lovelace",
"address": {
"city": "London",
"country": "UK"
}
}
]One common approach is to flatten nested keys into dotted column names. The same record could become:
name,address.city,address.country
Ada Lovelace,London,UKFlattening preserves individual values while making the hierarchy visible in the headers. For arrays, decide whether each item should become a separate row, a joined cell, or its own related file. Pick a rule that the receiving spreadsheet or importer can understand.
Common pitfalls
Assuming every row has the same keys
API records may omit optional fields. Build the column set from all records or explicitly define the schema, then leave a cell empty when a record has no value.
Forgetting CSV quoting rules
Fields containing commas, double quotes, or newlines should be wrapped in double quotes. A quote within a quoted field is escaped by doubling it. For example, "She said ""hello""".
Confusing empty values with missing fields
An empty string, a missing property, and a JSON null can mean different things. Decide how each should appear in the CSV and document that convention.
Skipping a review before import
Open a sample of the output and verify headers, row counts, special characters, and nested data before using it for reporting or bulk imports.
Frequently asked questions
Can every JSON document be converted directly to CSV?
Not without choosing how to represent its structure. CSV is tabular, so nested objects and arrays need to be flattened, serialized, or split into separate tables.
How are commas and quotes handled in CSV?
Fields containing commas, double quotes, or line breaks should be quoted. A double quote inside a quoted field is escaped by doubling it.
Does converting JSON to CSV preserve all data?
It can preserve scalar values when columns and rows are mapped deliberately, but CSV does not natively represent nested types. Decide how to flatten or encode those values before converting.
Can I open the resulting CSV in Excel or Google Sheets?
Yes. CSV is widely supported by spreadsheet applications. Check the delimiter and character encoding if values display incorrectly after import.
Put it into practice
Turn your JSON into a spreadsheet.
Convert a JSON array to a clean CSV with TEO ToolKit’s browser converter.
Open JSON to CSV