JSON zu CSV
Konvertieren Sie JSON-Arrays in CSV-Format mit konfigurierbaren Trennzeichen und Headern
Converting JSON to CSV: Flattening Structured Data for Tabular Analysis
JSON (JavaScript Object Notation) is the lingua franca of web APIs, NoSQL databases, and modern application backends. Its nested, hierarchical structure excels at representing complex relationships — but when the goal is data analysis, spreadsheet import, or database ingestion, a flat tabular format like CSV becomes essential. This tool converts JSON arrays of objects into well-formed CSV output, handling the fundamental challenge of flattening hierarchical data into rows and columns while preserving data fidelity and offering configurable delimiter options for regional compatibility.
JSON Array Structures and Tabular Suitability
Not all JSON structures map naturally to CSV. The ideal input for JSON-to-CSV conversion is an array of homogeneous objects — each object represents a row, and each key represents a column. This pattern is extremely common in API responses, database exports, and log aggregations:
- Homogeneous arrays: Arrays where every object shares the same keys map directly to a table. Each key becomes a column header, and each object becomes a row. Example:
[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}] - Heterogeneous arrays: When objects have different keys, the converter must produce a superset of all keys as columns. Missing values become empty cells. This is common in NoSQL query results where documents have varying schemas.
- Single objects: A lone JSON object (not wrapped in an array) can be treated as a single-row table. Some converters auto-wrap single objects in an array for convenience.
- Nested arrays within objects: When a field contains an array value (e.g.,
"tags": ["frontend", "react"]), the converter must decide how to represent it — joined as a delimited string, serialized as JSON, or expanded into multiple columns. - Primitive arrays: Arrays of scalar values (
[1, 2, 3]) lack key names entirely and require either positional column headers or a single-column output.
The quality of a JSON-to-CSV conversion depends on how well the source JSON matches the tabular model. Flat arrays of uniform objects produce perfect CSV output. Deeply nested or polymorphic structures require flattening strategies that inevitably lose some structural information — understanding these tradeoffs is critical for choosing the right approach.
Flattening Strategies for Nested JSON Objects
Real-world JSON data rarely consists of perfectly flat objects. API responses include nested addresses, embedded metadata, and related sub-objects. Flattening transforms these hierarchical structures into flat key-value pairs suitable for CSV columns:
- Dot notation flattening: The most common strategy. Nested keys are joined with dots to form compound column names. An object
{"user": {"name": "Alice", "email": "a@b.com"}}becomes columnsuser.nameanduser.email. This preserves the path hierarchy in column names and is reversible. - Bracket notation flattening: Array indices are represented with brackets:
items[0].name,items[1].name. This handles arrays within objects but can produce many columns if arrays are long. Common in form data serialization and query string encoding. - Underscore concatenation: Similar to dot notation but uses underscores:
user_name,user_email. Avoids conflicts with column names containing literal dots but may clash with existing underscore-separated keys. - Depth-limited flattening: Only flatten to a specified depth (e.g., 2 levels). Beyond that depth, nested values are serialized as JSON strings in the cell. Balances readability with completeness for deeply nested structures.
- JSON serialization for complex values: When a nested value cannot be meaningfully flattened (e.g., an array of objects), serialize it as a JSON string within the CSV cell. The cell content becomes
"[{""id"":1},{""id"":2}]"with properly escaped quotes.
Each strategy involves tradeoffs between column count, readability, and data loss. Dot notation is the industry default because it produces predictable column names that can be programmatically unflattened back to the original nested structure. Bracket notation extends this to handle arrays but can produce wide datasets when arrays have many elements.
Tabular vs Hierarchical Data: When Conversion Makes Sense
JSON and CSV represent fundamentally different data models. Understanding when conversion is appropriate — and when it loses too much information — prevents frustration and data quality issues:
- Good candidates for conversion: API responses that return collections of records (users, orders, products), log entries with consistent schemas, database query results serialized as JSON, and flat configuration exports.
- Poor candidates: Deeply nested tree structures (file systems, organizational hierarchies), graph data with circular references, documents with highly variable schemas, and JSON containing large embedded binary data (Base64 blobs).
- Data analysis workflows: CSV is the universal input format for spreadsheet applications (Excel, Google Sheets), statistical tools (R, pandas), and business intelligence platforms. Converting API responses to CSV enables non-technical stakeholders to analyze data using familiar tools.
- Database import: Relational databases import CSV efficiently via bulk load operations (
COPYin PostgreSQL,LOAD DATA INFILEin MySQL). Converting JSON API exports to CSV is often the fastest path to populating SQL tables. - Information loss: CSV cannot represent nested relationships within a single row without serialization hacks. A JSON object with an array of related items (e.g., an order with multiple line items) must either be denormalized into multiple rows or have the array serialized as a string.
The rule of thumb: if your JSON data answers the question "what are the attributes of each item in this collection?" it converts well to CSV. If it answers "how do these items relate to each other hierarchically?" CSV is the wrong target format.
Delimiter Options and Regional Configuration
While CSV technically stands for "Comma-Separated Values," the delimiter choice varies by region, application, and data content. Choosing the correct delimiter avoids parsing errors and ensures compatibility with the target application:
- Comma (
,): The standard delimiter per RFC 4180. Universal in English-speaking regions. Used by default in Excel (US/UK locale), Google Sheets, and most programming libraries. Problematic when data values contain commas (requires quoting). - Semicolon (
;): Standard in European locales (Germany, France, Spain, Italy) where the comma is used as a decimal separator. Excel in these locales expects semicolons. Essential for financial data containing decimal numbers like1.234,56. - Tab (
\t): Produces TSV (Tab-Separated Values) files. Rarely occurs naturally in data, making it a safe delimiter choice. Preferred for datasets with many commas or semicolons in values. Directly pasteable into spreadsheet cells. - Pipe (
|): Common in legacy mainframe systems and data warehousing. Useful when data contains both commas and semicolons. Less human-readable but highly reliable as a separator. - Custom delimiters: Some tools accept arbitrary single-character delimiters. The ASCII unit separator (
\x1F) is theoretically ideal — it never appears in text data — but few applications support it visually.
Beyond delimiters, CSV generation involves decisions about quoting strategy (quote all fields vs. quote only when necessary), line endings (CRLF for Windows compatibility per RFC 4180, LF for Unix systems), and header row inclusion. A well-configured JSON-to-CSV converter exposes these options to handle the full spectrum of target applications.
Code Examples
Converting a JSON Array of Objects to CSV with Nested Flattening
[
{
"id": 1,
"name": "Alice Johnson",
"email": "alice@example.com",
"address": {
"city": "Portland",
"state": "OR"
},
"tags": ["admin", "active"]
},
{
"id": 2,
"name": "Bob Smith",
"email": "bob@example.com",
"address": {
"city": "Seattle",
"state": "WA"
},
"tags": ["user"]
}
]Output:
id,name,email,address.city,address.state,tags
1,Alice Johnson,alice@example.com,Portland,OR,"admin,active"
2,Bob Smith,bob@example.com,Seattle,WA,userStandards & Specifications
- RFC 4180 — Common format and MIME type for CSV files — defines quoting rules, delimiter conventions, and header row expectations for the output format
Häufig Gestellte Fragen
What JSON format is required?
The input must be a JSON array of objects. Each object represents a row, and the object keys become column headers. For example: [{"name":"Alice","age":28}, {"name":"Bob","age":34}]. The tool will not work with single objects, arrays of primitives, or nested arrays.
How are headers determined?
Headers are automatically detected from all unique keys across all objects in the array. If different objects have different properties, the CSV will include all unique keys as columns. Rows with missing properties will have empty cells in those columns.
Can I convert nested JSON objects?
Yes, but with limitations. Nested objects are flattened using dot notation (e.g., "user.address.city" becomes a single column). Arrays within objects are converted to JSON strings. For complex nested structures, you may want to flatten your JSON first using a JSON transformer.
Which delimiter should I use?
Use comma (,) for standard CSV files compatible with most applications. Use semicolon (;) for European locales where comma is the decimal separator. Use tab (\t) for TSV files or when data contains many commas. Use pipe (|) when data contains commas and quotes.
What happens with large JSON files?
For files larger than 100KB, the tool automatically uses Web Workers to perform the conversion in a background thread. This prevents the browser from freezing and keeps the interface responsive. You'll see a processing indicator while the conversion is running.
Is my data sent to a server?
No, all JSON to CSV conversion happens entirely in your browser. Your data never leaves your device, ensuring complete privacy and security for sensitive information. This also means the tool works offline once the page is loaded.
Can I download the CSV file?
Yes! Click the "Download CSV" button to save the converted data as a .csv file to your computer. The file will be named with a timestamp for easy organization.
How do I open the CSV in Excel?
Simply download the CSV file and open it with Excel, Google Sheets, or any spreadsheet application. If you used a non-comma delimiter, you may need to use the "Import" feature in your spreadsheet app and specify the delimiter.