How to Convert JSON to CSV: Nested Data Guide
Converting hierarchical JSON datasets from web APIs, databases, and microservices into flat CSV spreadsheets is a daily necessity for software developers, data analysts, and business professionals.
Open JSON to CSV Converter Tool โThe Core Challenge: Hierarchical Trees vs. Tabular Grids
JavaScript Object Notation (JSON) is intrinsically a tree-like data structure. It allows arbitrary depth, where objects can hold child objects, arrays, and primitive values. In contrast, Comma-Separated Values (CSV) is strictly a two-dimensional grid consisting of columns (fields) and rows (records).
To successfully map a JSON tree into a CSV grid, the converter must solve two core architectural challenges: object flattening and RFC 4180 character escaping.
Mastering Dot Notation for Nested Objects
When an API returns nested child objects, standard industry convention utilizes dot notation to preserve relational lineage within flat spreadsheet column headers. For example, consider an API returning order information with shipping details:
// Original Hierarchical JSON:
{
"orderId": "ORD-5842",
"customer": {
"name": "Marcus Aurelius",
"shipping": {
"city": "Rome",
"postalCode": "00118"
}
},
"total": 149.50
}
By recursively walking child keys, the converter translates this nested object into four flat columns:
orderId,customer.name,customer.shipping.city,customer.shipping.postalCode,total
ORD-5842,"Marcus Aurelius",Rome,00118,149.50
When opened in Microsoft Excel or Google Sheets, each nested property occupies its own distinct column, enabling sorting, filtering, and pivot-table aggregation.
RFC 4180 Escaping Rules: Preventing Broken Spreadsheets
Many homemade conversion scripts fail when text values contain punctuation. Under the international RFC 4180 standard, specific escaping rules must be enforced:
- Delimiters Inside Values: If a text string contains a comma (e.g.
"Austin, TX") or selected delimiter, the entire string must be enclosed in quotes:"Austin, TX". Without quotes, spreadsheet programs treat the comma as a new column, shifting all subsequent fields to the right. - Double Quotes Inside Values: If a field contains quotes (e.g.
15" Screen), the internal quotation mark must be escaped by prefixing it with an additional quotation mark:"15"" Screen". - Line Breaks Inside Values: Multi-line descriptions and address strings must be enclosed in quotes so that spreadsheet engines treat the newline as part of the cell rather than the start of a new row.
Handling Missing or Inconsistent Keys Across Records
Because JSON is schema-less, different records in the same array often have missing or optional keys. A robust converter must perform a two-pass scan:
- Header Collection Pass: Iterate across all objects in the input array to construct a global set of all unique property keys.
- Row Generation Pass: Iterate across each record and emit a value for every global header key. If a record lacks a specific property, an empty string (
"") is output to preserve alignment.
Delimiters: Comma vs Semicolon vs Tab
| Delimiter | Format Name | Primary Regional or Software Use Case |
|---|---|---|
Comma (,) |
Standard CSV | United States, United Kingdom, Canada, Australia, and universal REST APIs |
Semicolon (;) |
European CSV | Germany, France, Italy, and Spain (where commas serve as decimal marks) |
Tab ( ) |
TSV (Tab-Separated) | Bioinformatics, database bulk copying, and direct copy-paste into Excel grids |
Frequently Asked Questions
What is dot notation in JSON flattening?
Dot notation joins parent and child property names with a period (for example, user.address.city) to represent deep object hierarchies inside a flat spreadsheet column.
How do you escape commas and quotes in CSV files?
Under RFC 4180 rules, any cell containing commas, newlines, or quotes must be enclosed in double quotes. Internal quotes must be escaped by doubling them (e.g. \"\"text\"\").
Why is JSON difficult to represent in spreadsheets?
JSON supports arbitrary nesting, arrays of mixed types, and key polymorphism, whereas spreadsheets demand uniform, two-dimensional tabular rows and columns.
How can I convert large JSON payloads without crashing my browser?
Use streaming or client-side batching tools like ToolNovus that avoid deep recursive call stack limits and execute within local memory.
Can Excel open CSV files with semicolon delimiters?
Yes. European versions of Microsoft Excel use semicolons by default because commas are reserved for decimal points in European number formatting.
Last reviewed: November 2026 โข Published by ToolNovus