JSON to CSV Converter Online

Convert JSON arrays to CSV format. Handles nested objects/arrays, RFC 4180 quoting. Downloads as .csv for Excel or Google Sheets.

JSON to CSV converts a JSON array of objects into comma-separated values using Papa Parse. Object keys become column headers; values become rows. Nested objects and arrays are written as JSON strings in a single cell, not flattened into dotted columns. Download saves the result as converted.csv. Nothing is uploaded.

JSON
CSV

How it works

  1. Input: Paste JSON directly, upload a .json or .txt file, or use the sample data button. All processing happens in your browser.
  2. Parse: The tool runs JSON.parse (RFC 8259) and expects an array of objects or a single object. Arrays of primitives, arrays of arrays, and JSON Lines (NDJSON) are not supported.
  3. Generate columns: Column headers are the union of all object keys across rows, in first-seen order. Missing keys produce empty cells. Nested objects/arrays are serialized to JSON strings.
  4. Output: Papa.unparse generates RFC 4180 compliant CSV with proper quoting and CRLF line endings.
  5. Download: Click "Download CSV" to save as converted.csv. Open it in Excel, Google Sheets, or any spreadsheet application.

Handling nested objects and arrays

CSV is a flat format — it doesn't natively support nested data. When your JSON contains nested objects or arrays, this tool converts them to JSON strings:

Example: Nested object

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

Becomes: name,address then Ada,"{""city"":""London"",""country"":""UK""}"

Example: Nested array

[{"name": "Ada", "tags": ["developer", "speaker"]}]

Becomes: name,tags then Ada,"[""developer"",""speaker""]"

The doubled quotes ("") are RFC 4180 escaping — spreadsheet applications will interpret them correctly.

Opening CSV in Excel or Google Sheets

  1. Download: Click "Download CSV" to save converted.csv to your computer.
  2. Excel: Double-click the file to open it directly, or use File → Open in Excel. Excel auto-detects the comma delimiter.
  3. Google Sheets: Go to File → Import → Upload, select the CSV, then choose "Comma" as the separator if prompted.

The CSV uses CRLF line endings and RFC 4180 quoting, which are compatible with virtually all spreadsheet applications. Nested JSON data appears as text in cells — you can use spreadsheet formulas to parse it further if needed.

json2csv: JSON to CSV in JavaScript, Node and Python

Need to convert JSON to CSV programmatically? Here are examples for common environments.

Browser JavaScript with Papa.unparse

Papa Parse works client-side. Pass an array of objects to Papa.unparse:

import Papa from 'papaparse';

const data = [
  { name: 'Ada', age: 30, city: 'London' },
  { name: 'Bob', age: 25, city: 'Paris' }
];

const csv = Papa.unparse(data);
// "name,age,city\r\nAda,30,London\r\nBob,25,Paris"

Node.js with @json2csv/plainjs

The @json2csv/plainjs package (v6+) handles synchronous conversion; use @json2csv/node for streaming large files:

import { Parser } from '@json2csv/plainjs';

const data = [
  { name: 'Ada', age: 30, city: 'London' },
  { name: 'Bob', age: 25, city: 'Paris' }
];

const parser = new Parser({ fields: ['name', 'age', 'city'] });
const csv = parser.parse(data);

Python with csv.DictWriter

The standard library csv module handles simple cases:

import csv
import io

data = [
    {'name': 'Ada', 'age': 30, 'city': 'London'},
    {'name': 'Bob', 'age': 25, 'city': 'Paris'}
]

output = io.StringIO()
writer = csv.DictWriter(output, fieldnames=['name', 'age', 'city'])
writer.writeheader()
writer.writerows(data)
print(output.getvalue())

Python with pandas (nested JSON)

For nested or complex JSON, use pandas.json_normalize to flatten first:

import pandas as pd

data = [
    {'name': 'Ada', 'address': {'city': 'London', 'zip': 'SW1'}},
    {'name': 'Bob', 'address': {'city': 'Paris', 'zip': '75001'}}
]

df = pd.json_normalize(data)
# Columns: name, address.city, address.zip
df.to_csv('output.csv', index=False)

JSON to CSV in the shell

There is no POSIX JSON-to-CSV converter. jq 1.7 @csv writes one CSV row from a JSON array. Map each object to a field array first — @csv on an object errors object cannot be csv-formatted, only array. jq quotes every string; Papa.unparse on this page quotes only when a field contains a comma, quote, or newline. Numbers stay unquoted in both. jq writes LF between rows; this page writes RFC 4180 CRLF. jq is not POSIX.

jq @csv

Pass -r so the row is CSV, not a JSON string of CSV. List the columns; jq does not build a header from object keys unless you emit keys_unsorted first. keys sorts alphabetically. .[0] | keys_unsorted uses only the first object, so a later city key is dropped. An empty array with that header form errors null (null) has no keys:

printf '%s' \
  '[{"name":"John Doe","age":30,"email":"john@example.com","city":"New York"},{"name":"Jane Smith","age":25,"email":"jane@example.com","city":"Los Angeles"},{"name":"Bob Johnson","age":35,"email":"bob@example.com","city":"Chicago"}]' \
  | jq -r '(.[0]|keys_unsorted), (.[] | [.name,.age,.email,.city]) | @csv'
# "name","age","email","city"
# "John Doe",30,"john@example.com","New York"
# "Jane Smith",25,"jane@example.com","Los Angeles"
# "Bob Johnson",35,"bob@example.com","Chicago"

printf '%s' \
  '[{"name":"John Doe","age":30,"email":"john@example.com","city":"New York"}]' \
  | jq '.[] | [.name,.age,.email,.city] | @csv'
# "\"John Doe\",30,\"john@example.com\",\"New York\""

printf '%s' '[{"name":"Ada"}]' | jq -r '.[] | @csv'
# jq: error (at <stdin>:0): object ({"name":"Ada"}) cannot be csv-formatted, only array

printf '%s' '[{"name":"Ada"},{"name":"Bob","city":"Paris"}]' \
  | jq -r '(.[0]|keys_unsorted) as $k | $k, (.[] | [.[ $k[] ]]) | @csv'
# "name"
# "Ada"
# "Bob"

Nested values with tojson

A nested object or array is not a CSV cell. tojson first — the same JSON-in-one-cell shape this page writes with JSON.stringify, not pandas json_normalize dotted columns. jq still quotes Ada; this page leaves that name unquoted:

printf '%s' \
  '[{"name":"Ada","address":{"city":"London","country":"UK"}}]' \
  | jq -r '.[] | [.name,.address] | @csv'
# jq: error (at <stdin>:0): object ({"city":"Lo...) is not valid in a csv row

printf '%s' \
  '[{"name":"Ada","address":{"city":"London","country":"UK"}}]' \
  | jq -r '.[] | [.name, (.address|tojson)] | @csv'
# "Ada","{""city"":""London"",""country"":""UK""}"

printf '%s' \
  '[{"name":"Ada","tags":["developer","speaker"]}]' \
  | jq -r '.[] | [.name, (.tags|tojson)] | @csv'
# "Ada","[""developer"",""speaker""]"

jq reads a stream of JSON values, so two objects on separate lines convert without wrapping them in [ ]. This page's JSON.parse rejects that JSON Lines input. jq 1.7 has no fromcsv — @csvd errors csvd is not a valid format. Parse CSV on the CSV to JSON converter, or with the Python csv.DictWriter snippet above (that dialect quotes like this page and uses CRLF). @tsv is tab-separated and does not quote John Doe — not this converter. Pretty-print JSON in the shell belongs on the JSON formatter, not here.

FAQ

Does this tool upload my JSON?
No. All conversion runs in your browser using Papa Parse. Your data is never sent to a server.
What JSON structures are supported?
An array of objects works best, or a single object (one row). Nested objects and arrays are not flattened into dotted columns such as address.city. They are serialized with JSON.stringify and written as one quoted CSV cell. Flatten the JSON first if you need one column per nested key.
How are column headers determined?
Column headers come from the object keys. Papa Parse extracts all unique keys across the array to build the header row.
Can I open the CSV in Excel or Sheets?
Yes. Download the CSV file and open it in Excel, Google Sheets, or any spreadsheet application.
What delimiter is used?
The tool uses commas by default. If your values contain commas, they are automatically quoted per RFC 4180.
Why are my numbers changing?
JavaScript uses IEEE-754 floating point for numbers. Integers larger than 2^53 − 1 (about 9 quadrillion) lose precision. Keep large IDs as quoted strings in your JSON if exact values matter.
Can I convert JSON Lines (NDJSON) to CSV?
Not directly. JSON Lines puts one JSON object on each line with no array brackets or commas between them. Add a comma after each line except the last and wrap everything in [ ], or convert it with an NDJSON tool, before pasting here.

Related