Flatten Nested JSON
Collapse any deeply nested JSON object into a single level of dot-notation keys. Paste a response from any API — Stripe, HubSpot, Salesforce — and get a flat, spreadsheet-ready object back.
How flattening works
Nested objects → dot-notation keys
{ user: { address: { city: "NYC" } } } becomes { "user.address.city": "NYC" }. Every nested path is encoded in the key name.
Arrays → indexed entries
{ orders: [{ id: 1 }, { id: 2 }] } becomes { "orders[0].id": 1, "orders[1].id": 2 }. No data is dropped.
Configurable depth control
Flatten completely, or stop at a specific depth. max depth=2 flattens two levels and leaves deeper objects intact as JSON strings.
Configurable separator
Dot notation is the default. Switch to underscore (user_address_city) for database column names, or slash for path-style keys.
When to use this
Before JSON → CSV conversion
Most CSV converters produce [object Object] when they hit a nested field. Flatten first, then convert — every value becomes a scalar.
Before database INSERT
SQL columns expect scalar values. A nested API response needs to be flattened before you can map fields to table columns.
For API response comparison
Diffing two nested objects is hard to read. Flatten both to dot-notation keys and the diff becomes a clean, key-by-key comparison.
Normalizing logs and telemetry
Systems like Elasticsearch and Datadog work best with flat JSON. Deeply nested events can cause field type conflicts across index shards.
Example
Stripe Payment Intent — 3 levels of nesting, flattened to dot-notation keys
{
"id": "pi_3MtwBwLkdIwHu7ix",
"amount": 2000,
"customer": {
"id": "cus_NffrFeUfNV2Hib",
"email": "jenny@example.com"
},
"payment_method": {
"type": "card",
"card": {
"brand": "visa",
"last4": "4242"
}
}
}{
"id": "pi_3MtwBwLkdIwHu7ix",
"amount": 2000,
"customer.id": "cus_NffrFeUfNV2Hib",
"customer.email": "jenny@example.com",
"payment_method.type": "card",
"payment_method.card.brand": "visa",
"payment_method.card.last4": "4242"
}3 levels of nesting collapsed into 7 flat keys. Every value is now a scalar — ready to map to CSV columns or SQL fields without any further processing.
Frequently asked questions
What happens to arrays when I flatten JSON?
By default, each array element gets an indexed key: orders[0].id, orders[1].id. You can switch to inline mode, which joins primitive arrays into a pipe-delimited string instead.
How deep does flattening go by default?
All the way — unlimited depth. If your JSON is nested 10 levels deep, all 10 levels are collapsed into the key path. Use the max depth option to stop at a specific level.
Can I flatten just one level instead of all the way?
Yes. Set max depth to 1 and only the top level of nesting is flattened. Deeper objects are preserved as JSON strings in the output value.
My JSON has arrays of objects — should I flatten or expand to rows?
Flatten works well for short arrays and primitive values. For arrays where each element is a meaningful record (like order line items or transaction history), row expansion is usually better — each element becomes its own CSV row with parent fields repeated. Our JSON to CSV converter handles both.
What is the difference between dot notation and underscore notation?
Only the separator character. user.address.city with dot notation becomes user_address_city with underscores. Use underscores when the output will be used as a variable name or database column name where dots aren't legal identifiers.
Related Tools
All conversions run in your browser — nothing is uploaded.
Browse all 26 converters →