正在加载,请稍候…

JSON to CSV Converter: Export Data for Spreadsheets

Convert JSON arrays to CSV format for use in Excel, Google Sheets, and data analysis tools. Automatically detects column headers, handles nested objects, and supports one-click download.

Why Convert JSON to CSV?

JSON is the de facto standard for web APIs and configuration, while CSV (Comma-Separated Values) is the universal format for spreadsheets, data analysis, and database imports. Converting between them is a fundamental data engineering task.

When you need JSON-to-CSV:

  • Exporting API data to Excel or Google Sheets for analysis
  • Loading web application data into database tables
  • Creating reports from JSON-structured data sources
  • Sharing structured data with non-technical stakeholders
  • Feeding data into machine learning pipelines that expect tabular format

JSON Structures and CSV Mapping

Flat JSON Array (Simple Case)

[
  {"id": 1, "name": "Alice", "email": "alice@example.com"},
  {"id": 2, "name": "Bob", "email": "bob@example.com"}
]

Maps directly to CSV:

id,name,email
1,Alice,alice@example.com
2,Bob,bob@example.com

Nested Objects (Challenge)

[
  {
    "id": 1,
    "user": {"name": "Alice", "age": 28},
    "address": {"city": "NYC", "country": "US"}
  }
]

Options for handling nesting:

  1. Flatten: user.name, user.age, address.city, address.country
  2. JSON stringify: Keep nested objects as JSON strings in the CSV cell
  3. Ignore: Omit nested objects

Flattening is usually preferred for analysis.

Arrays Within Objects (Challenge)

[
  {"id": 1, "name": "Alice", "tags": ["admin", "editor"]}
]

Options:

  1. Join: "admin,editor" (pipe or comma separated in a single cell)
  2. One row per value: Creates multiple CSV rows per JSON object
  3. Multiple columns: tag1, tag2, etc.

CSV Format Specification (RFC 4180)

Basic Rules

  • Fields separated by commas
  • Records separated by newlines (CRLF in RFC 4180)
  • Optional header row
  • Fields may be quoted with double quotes
  • Quoted fields may contain commas and newlines
  • To include a double quote: "" (escape by doubling)

Common Variations

CSV isn't fully standardized. Variations include:

  • Delimiter: tab (\t), semicolon (;), pipe (|) instead of comma
  • Quote character: Single quotes or no quotes
  • Line endings: LF (Unix) vs. CRLF (Windows)
  • Encoding: UTF-8, UTF-8 with BOM, Latin-1

Microsoft Excel uses semicolons as the default delimiter in many European locales (where commas are decimal separators), causing countless CSV parsing headaches.

Handling Special Cases

Empty Values

{"id": 1, "name": null, "email": ""}

Null and empty string are both represented as empty CSV cells but have different semantics.

Boolean Values

true and false in JSON become the strings "true" and "false" in CSV unless explicitly converted.

Numeric Precision

JSON numbers can represent arbitrary precision floats. CSV transmits them as strings. Be cautious of floating-point precision loss during the round-trip.

Unicode and Special Characters

All Unicode characters should be preserved. Cells containing commas, quotes, or newlines must be properly quoted.

Programmatic Conversion

JavaScript

function jsonToCsv(data) {
  const headers = Object.keys(data[0]);
  const rows = data.map(obj =>
    headers.map(h => JSON.stringify(obj[h] ?? '')).join(',')
  );
  return [headers.join(','), ...rows].join('\n');
}

Python (pandas)

import pandas as pd
import json

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

df = pd.json_normalize(data)  # Handles nested objects
df.to_csv('output.csv', index=False)

Command Line (jq)

jq -r '["id","name","email"], (.[] | [.id, .name, .email]) | @csv' data.json

Using the JSON-to-CSV Converter

Our tool:

  1. Paste JSON data — arrays of objects or single objects
  2. Configure options — delimiter choice, quote handling, nested object strategy
  3. Preview the output — see the CSV table before downloading
  4. Handle arrays — choose how to represent array values
  5. Download CSV — get the file ready for Excel or database import
  6. Copy to clipboard — paste directly into spreadsheets

The tool handles edge cases automatically: proper quoting of fields containing commas, escaping double quotes, and consistent column ordering from potentially inconsistent JSON objects.