Turn deeply nested JSON into a single-level object with path keys like user.address.city or orders[0].sku, or rebuild nested JSON from flat keys. Choose the separator and array style; numbers and key order are preserved exactly.
Last updated:
Everything runs in this tab: your JSON is never uploaded. Big numbers and key order are kept exactly. Tip: Ctrl + Enter runs.
Advertisement
Advertisement
How to use the JSON Flatten / Unflatten
Choose Flatten or Unflatten with the tabs at the top. A sample is loaded so you can see the result right away.
Paste your JSON or open a .json file. In Unflatten mode, paste an object whose keys are paths, such as {"user.name": "Ada"}.
Set the separator and array style: dot, underscore or slash, and items.0 or items[0] for array indexes.
Adjust the extras: levels to flatten, keeping empty {} and [], sorting keys, or numeric keys creating arrays.
Copy or download the result, or press Swap to feed it back in and check the round trip.
Flatten and unflatten example
Nested JSON on the left, the flattened version with the default dot separator on the right. Unflatten turns the right side back into the left side exactly.
Different tools expect different path formats. Pick the one your destination understands:
Setting
Path for the city of the first order
Typical use
Separator ., separator indexes
orders.0.address.city
MongoDB dot notation, Elasticsearch fields, i18n files, lodash get
Separator ., bracket indexes
orders[0].address.city
JavaScript property paths, form field names, jq-style paths
Separator _
orders_0_address_city
CSV and spreadsheet column headers, SQL column names
Separator __
orders__0__address__city
Environment variables (for example ASP.NET Core configuration)
Separator /
orders/0/address/city
Paths similar to JSON Pointer (RFC 6901) and file-like keys
Tips for a lossless round trip
Keep empty objects and arrays. An empty {} or [] has no values to produce a path, so without this option it disappears when you flatten.
Choose a separator that is not in your keys. If a key such as "file.name" contains the separator, unflattening splits it into two levels. The tool warns you when this happens.
Numeric object keys. Keys such as "2024" or user IDs look like array indexes. Turn off Numeric keys create arrays when unflattening so they stay object keys.
Arrays with gaps. If a flat object has items.0 and items.3, the missing positions 1 and 2 are filled with null, because JSON arrays cannot have holes.
Frequently asked questions
What does flattening JSON mean?
Flattening turns a nested JSON structure into an object with only one level. Each key becomes the full path to a value, joined with a separator, so {"user": {"name": "Ada"}} becomes {"user.name": "Ada"}. Flat JSON is easier to load into spreadsheets, CSV files, search indexes, environment variables and translation (i18n) tools.
How are arrays flattened?
Each array item gets its index in the path. With the separator style, the second tag of a user becomes user.tags.1; with the bracket style it becomes user.tags[1], the notation used by JavaScript and many query languages. Unflatten understands both styles.
How does unflatten decide between objects and arrays?
When 'Numeric keys create arrays' is on, a path segment that is a whole number such as 0 or 12 creates an array, and bracket indexes like [0] always do. Missing indexes are filled with null. Turn the option off if your objects use numeric keys, such as IDs, that should stay object keys.
What happens if a key already contains the separator?
A key like "file.name" flattens to a path that looks like two levels, so unflattening would split it into file → name. The tool warns you when this happens; pick a separator that does not appear in your keys, such as / or __, to get a lossless round trip.
What are conflicting keys when unflattening?
A conflict happens when one key uses a path as a value and another uses it as a parent, for example "a": 1 together with "a.b": 2. A value cannot be both a number and an object, so the second key is skipped and listed in the message.
Are large numbers kept exactly?
Yes. The tool uses its own JSON parser that keeps every number exactly as written, so IDs larger than 9,007,199,254,740,991 (2^53 − 1) are not rounded as they would be by JavaScript's JSON.parse. Key order is also preserved.
Is my JSON uploaded anywhere?
No. Flattening and unflattening run entirely in JavaScript in this page, so your data never leaves your device.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.