Skip to content
← Code Tools

JSON to CSV (Deep)

Flatten nested JSON into a CSV with dot-notation columns

JSON to CSV Deep Flattener

A flat JSON-array-of-objects converts to CSV trivially — one row per object, one column per key. Real JSON is rarely flat: API responses, webhook payloads, log entries, and config files are routinely three or four levels deep with arrays mixed in. Most JSON-to-CSV converters stop at the first level and stringify the nested objects, which is the wrong answer almost every time. This tool walks the full tree, flattens object paths into dot-notation column headers, and handles arrays with a configurable strategy.

How Deep Flattening Works

The tool walks every object in the input array and collects every leaf path it encounters. A leaf path is the chain of keys leading to a primitive value: user.address.city, order.total, metadata.tags. Each unique leaf path becomes a CSV column. For a given row, if the path exists with a value, that value goes in the cell; if it does not exist (because that record happened not to have an address, say), the cell is empty. The column ordering is stable: top-level keys first in their original order, then nested keys grouped under their parent. The result is the natural flat representation a spreadsheet user expects.

Array Handling Strategies

Arrays are the hard case. The tool supports three strategies: join, explode, and index. Join concatenates array elements with a delimiter (comma by default) into a single cell — best for tag lists where order does not matter much. Explode duplicates the row once per array element, so a record with three tags becomes three rows, each carrying one tag plus identical values for every other column — best when you want to filter or pivot by the array element later. Index expands the array into separate columns (tags.0, tags.1, tags.2) — best when array position is meaningful and the array length is consistent.

Use Cases and Source Shapes

API responses where each record has nested address, billing, or metadata objects flatten cleanly with the join or index strategy. Webhook payloads where each event carries an array of items (line items, attendees, attachments) are best handled with explode — you get one row per item in the array, with the parent event repeated, which is the natural shape for analytics tools. Survey export JSON where every question is a key under a responses object becomes a wide CSV with one column per question. Log entries with nested context objects (request, user, environment) flatten to a CSV that opens cleanly in any spreadsheet for filter-and-sort work.

Edge Cases and How They Are Handled

Mixed types in the same array (sometimes string, sometimes object) cause the path-collection pass to record both shapes; the resulting CSV has all union columns and cells where a given record had the wrong shape are left empty. Null values are preserved as empty cells rather than the literal string null. Keys containing dots in their actual name (rare but legal in JSON) are bracketed in the path: data["my.key"].value. Very deep nesting (10+ levels) is handled correctly but produces wide CSVs that may be unwieldy in spreadsheet tools; consider whether deep flattening is actually what you want or whether a hierarchical view would be more useful.

Pair this with related tools: JSON ↔ CSV Converter for the flat case in either direction, JSON Formatter to inspect the source structure first, CSV Cleaner for post-conversion cleanup, and CSV Row Filter to slice the result. The deep flattener is most useful as the first step in a pipeline that ends in a spreadsheet or a SQL table.

Frequently Asked Questions

Does the converter upload my JSON file?+
No. The JSON is parsed locally in your browser, walked to collect paths, and written to a CSV in memory. The output is offered as a download. Nothing is uploaded. The Network tab during conversion shows zero requests.
How are nested objects flattened?+
Object keys are joined with dots to form column headers: user.address.city. The walker visits every leaf value across every record in the input array, collects the set of unique paths, and emits one column per path. Records that do not have a given path get an empty cell.
How are arrays handled?+
Three strategies: join (concatenate elements into one cell with a delimiter), explode (duplicate the row once per array element), or index (expand into tag.0, tag.1 columns). Pick whichever matches the shape you want the CSV to have downstream.
What if my JSON is not an array of objects?+
The tool requires the top level to be an array. If the top level is an object, wrap it in an array first ([ at the start and ] at the end), or if there is a single property that holds the array of interest, paste that property's value in instead. JSON Formatter helps with the inspection step.
Are null and undefined values preserved?+
Null in the source becomes an empty cell in the CSV (not the literal string null). Undefined paths — keys that simply do not exist on a given record — also become empty cells. There is no way in CSV to distinguish these two cases, which is a known limitation of the format itself.
Can I see which columns will be generated before converting?+
Yes. The preview pane shows the full sorted list of paths discovered during the walk, with sample values from the first few records. You can deselect paths you do not want in the output to reduce the CSV width.
What is the file size limit?+
No hard cap. JSON files up to a few hundred megabytes work fine. Very large files (multi-gigabyte) may exhaust browser memory, since the walker holds the parsed JSON tree in memory; in those cases, split the file into chunks at the top-level array and process them separately.
Why is this different from a regular JSON to CSV converter?+
Regular converters stop at the first level and stringify nested objects, producing cells with raw JSON in them. This converter walks the full tree and flattens object paths into separate columns, which is what spreadsheet, database, and analytics tools actually want. For genuinely flat JSON, the regular converter is fine; for deeply nested API responses or webhook payloads, the deep flattener saves a Pandas script.

Built by Derek Giordano · Part of Ultimate Design Tools

Privacy Policy · Terms of Service