Flatten JSON Arrays Online
Turn nested arrays of API records into readable flat paths such as orders.0.items.0.sku so you can inspect, export, and debug row-like JSON faster.
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:
- Arrays of API records
- Nested order line items
- Event batches and logs
- CSV and spreadsheet prep
Example: input → output
Flatten nested JSON arrays
Arrays are where flattening stops being obvious. A single object can become one flat map, but an array might mean "one flat object per row" or "expand every item with an index." Order payloads, event batches, search results, and analytics logs all use arrays differently, so the right JSON flattener behavior depends on the destination.
This page focuses on flattening JSON arrays online. It uses the same engine as the Flatten JSON tool, but the examples here are written for arrays of records and nested list fields.
JSON array flattener example
Input:
[
{
"id": "ord_1",
"customer": { "email": "ada@example.com" },
"items": [
{ "sku": "book", "qty": 2 },
{ "sku": "pen", "qty": 4 }
]
}
]Flattened with indexed array paths:
[
{
"id": "ord_1",
"customer.email": "ada@example.com",
"items.0.sku": "book",
"items.0.qty": 2,
"items.1.sku": "pen",
"items.1.qty": 4
}
]That format is useful for quick QA review because every nested value has a visible path. It is less ideal when the array can contain hundreds of items, because each index can become a separate column.
When to flatten arrays by index
Index-based flattening is best when each record has a small, predictable number of child items. Examples include two addresses, three attribution fields, one latest invoice, or a small set of feature flags.
For long line-item arrays, indexed paths can create wide output. In that case, flatten the parent fields first, then normalize or explode line items into separate rows with a pipeline step. The parent order can keep order.id, while each item row gets items.sku, items.qty, and items.price.
Flatten array of objects for CSV
CSV exporters usually want an array of flat objects:
[
{ "user.name": "Ada", "user.plan": "pro" },
{ "user.name": "Grace", "user.plan": "team" }
]That shape converts cleanly because every object becomes one row. If your next step is spreadsheet export, pair this page with Flatten JSON for CSV and then JSON to CSV.
Common array flattening mistakes
- Flattening huge arrays into
items.0,items.1,items.2columns when the destination really needs separate rows. - Forgetting that missing items produce empty CSV cells.
- Treating arrays of primitives and arrays of objects the same way.
- Losing item order when downstream tools sort columns alphabetically.
- Using
.as a delimiter when original keys already contain dots.
Array flattening vs unflattening
Indexed paths can usually be rebuilt if the delimiter and indexes are preserved. For example, items.0.sku and items.1.sku can become an items array again. Use Unflatten JSON when a flat array path map needs to become nested JSON for an API request.
Related flatten JSON tools
- JSON flattener - the general-purpose flatten and nest tool.
- Flatten JSON for CSV - turn nested paths into spreadsheet columns.
- Flatten API Response JSON - inspect nested REST, GraphQL, and webhook payloads.
- Unflatten JSON - rebuild arrays and objects from indexed flat paths.
Frequently asked questions
Can this flatten an array of JSON objects?+−
Yes. An array of objects can be flattened into an array of flat objects, which is the most useful shape for CSV, spreadsheet, and QA workflows.
What happens to arrays inside each record?+−
They can stay as arrays or expand into indexed paths such as items.0.sku and items.1.sku. Indexed paths are useful for small arrays but can create many columns for long lists.
Should I flatten arrays before CSV export?+−
Usually yes, if the arrays are small and predictable. For long line-item arrays, normalize them into separate rows instead of creating hundreds of indexed 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}