Flatten JSON for CSV Export
Convert nested JSON into stable column paths before exporting to CSV, Excel, Sheets, Power BI, or any reporting workflow that expects rows and columns.
Paste your JSON → Get results instantly (no signup)
→ Flatten or nest keys in this JSON structure and flatten nested object.
1{2 "user.name": "Alice",3 "user.address.city": "NYC",4 "user.address.zip": "10001"5}Love the result?
Use this exact pipeline in your app, backend, or LLM workflow.
No setup needed. Works with curl, Node, Python.
Uses example data. For edited input, copy from the playground.
Works with:
- JSON to CSV conversion
- Excel and Google Sheets
- Power BI and Tableau
- Reporting exports
Example: input → output
Flatten JSON before CSV export
CSV is a table format, so it cannot represent nested objects directly. If you convert nested JSON to CSV too early, fields like customer, address, and metadata often become stringified blobs in one cell. Flattening JSON first turns nested paths into useful columns such as customer.email, shipping.address.city, and plan.interval.
This page is for the spreadsheet and reporting workflow. It uses the same browser-based engine as the Flatten JSON tool, but the examples focus on CSV, Excel, Google Sheets, Power BI, Tableau, and BI handoffs.
Nested JSON to CSV-ready columns
Input:
[
{
"customer": {
"email": "ada@example.com",
"company": "Analytical Engines"
},
"invoice": {
"total": 129,
"currency": "USD"
}
}
]Flattened output:
[
{
"customer.email": "ada@example.com",
"customer.company": "Analytical Engines",
"invoice.total": 129,
"invoice.currency": "USD"
}
]Those keys become clean CSV headers. Finance, ops, and customer-success teams can filter by invoice.currency or customer.company without opening nested JSON in a single cell.
How to flatten JSON for Excel
- Paste the nested JSON array.
- Flatten nested objects into dotted paths.
- Check whether arrays should stay arrays or expand by index.
- Send the flat output to JSON to CSV or JSON to Excel.
- Open the CSV in Excel, Google Sheets, Numbers, or a BI tool.
If the data has inconsistent records, run Normalize JSON before export so each row has the same expected columns.
CSV edge cases
Flat JSON still needs a little care before CSV export. Long numeric IDs may be interpreted by Excel as numbers. Timestamps can be auto-converted to local date formats. Arrays can create either indexed columns or string values. Missing keys turn into empty cells. These are spreadsheet issues, not JSON issues, but flattening makes them easier to see before the export.
Flatten vs direct conversion
Direct JSON to CSV conversion is fine for already-flat arrays:
[{ "id": 1, "email": "ada@example.com" }]Flatten first when the record contains objects:
[{ "user": { "id": 1, "email": "ada@example.com" } }]Without flattening, the user object may become a string in one CSV cell. With flattening, user.id and user.email become separate columns.
Related CSV workflows
Use Flatten JSON Array when child arrays are the hard part. Use Flatten API Response JSON when the source is a REST, GraphQL, or webhook payload. Return to the main JSON flattener for the general-purpose tool page and reverse nesting option.
Related flatten JSON tools
- JSON flattener - flatten nested JSON objects and arrays online.
- Flatten JSON Array - handle indexed array paths before export.
- Flatten JSON in JavaScript - compare output with JS flatten helper behavior.
- Unflatten JSON - convert flat CSV-style keys back into nested JSON.
Frequently asked questions
Why flatten JSON before converting to CSV?+−
CSV is flat. Flattening first turns nested paths into column names, so fields like customer.email and invoice.total become separate columns instead of stringified objects.
Does flattened JSON work in Excel?+−
Yes. After flattening, convert the flat JSON array to CSV and open it in Excel, Google Sheets, Numbers, Power BI, or Tableau.
What if my JSON records have different fields?+−
You can still export them, but some cells will be empty. Normalize JSON first when every row needs the same set of columns.
Related tools
- Rename KeysRename known keys or convert key casing without changing the underlying values
- Find & ReplaceFind and replace matching keys or values across JSON using broad search patterns
- FilterFilter rows, items, keys, or values by explicit conditions and keep only the matches you want
- Pick FieldsKeep only a known allowlist of fields and remove everything else
- RestructureFlexibly restructure collections by grouping, unwinding, transposing, or rearranging nested data
Read more on the blog
Advanced usage (optional)
Flatten / Nest
v1.0.0Description
Flatten / Nest
Convert between nested and flat object structures. Flatten deep objects into single-level key-value pairs, or nest flat keys back into hierarchical objects. Supports multiple key formats: delimiter-separated, camelCase, snake_case, PascalCase, and kebab-case.
Modes
Flatten
Convert nested objects into flat keys. Each nested path becomes part of the key name.
{ "user": { "name": "Alice" } } → { "user.name": "Alice" }Nest
Convert flat keys back into nested objects by splitting on the delimiter or case boundaries.
{ "user.name": "Alice" } → { "user": { "name": "Alice" } }Key Formats
Delimiter (default)
Join/split key segments with a character (default: .).
- Flatten:
user+name→user.name - Nest:
user.name→user/name
camelCase
Join/split on uppercase letter boundaries.
- Flatten:
user+address+city→userAddressCity - Nest:
userAddressCity→user/address/city
snake_case
Join/split on underscores.
- Flatten:
user+address+city→user_address_city - Nest:
user_address_city→user/address/city
PascalCase
Same as camelCase but with uppercase first letter.
- Flatten:
user+name→UserName
kebab-case
Join/split on hyphens.
- Flatten:
user+name→user-name
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
| Mode | enum | flatten | flatten or nest |
| Key Format | enum | delimiter | delimiter, camelCase, snake_case, PascalCase, or kebab-case |
| Delimiter | string | . | Character(s) used to join/split key segments (only for delimiter format) |
| Max Depth | number | 0 | Maximum nesting depth to flatten (0 = unlimited) |
| Target Paths | path-picker | [] | Scope operation to specific paths only (empty = apply everywhere) |
Use Cases
API Integration
- Flatten for forms: Convert nested API responses to flat form field names
- Nest for APIs: Convert flat form data back to nested API request bodies
- Format conversion: Transform between dot-notation and camelCase conventions
Database Operations
- MongoDB flattening: Flatten nested documents for tabular export
- SQL mapping: Convert hierarchical JSON to flat column names for SQL insertion
- Schema migration: Convert between naming conventions (snake_case ↔ camelCase)
Configuration Management
- Environment variables: Flatten config objects to dot-notation for
.envfiles - Depth limiting: Flatten only the first level while preserving deep structures
Configuration
| Name | Type | Default | Description |
|---|---|---|---|
| Mode | enum | flatten | flatten: convert nested objects to flat keys. nest: convert flat keys back to nested objects. flatten nest |
| Key Format | enum | delimiter | delimiter: use a character to join/split. Others: camelCase, snake_case, PascalCase, kebab-case. delimiter camelCase snake_case PascalCase kebab-case |
| Delimiter | string | . | Character(s) used to join/split key segments (default is dot) |
| Max Depth | number | 0 | Maximum nesting depth to flatten (0 = unlimited) |
| Target Paths | path-picker | [] | Scope operation to specific paths only (empty = apply everywhere) |
Examples
Flatten or nest keys in this JSON structure and flatten nested object.1{2 "user.name": "Alice",3 "user.address.city": "NYC",4 "user.address.zip": "10001"5}API Usage
curl -X POST https://your-domain.com/api/v1/utilities/structure.flatten-nest \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"inputs":{"primary":{"user":{"name":"Alice","address":{"city":"NYC","zip":"10001"}}}},"config":{"mode":"flatten","delimiter":".","maxDepth":0,"targetPaths":[]}}'1{2 "user.name": "Alice",3 "user.address.city": "NYC",4 "user.address.zip": "10001"5}