JSON Flattener

Turn nested JSON into a flat set of dot-notation keys, or turn flat keys back into nested JSON. Both directions are here because you need both: flattened keys are how environment variables, spreadsheet columns, form field names and many config formats express nesting, so going back is as common a task as going forward. Array indices can be written as `a.0` or `a[0]`, and the separator is yours to change. The thing this gets right that many flatteners do not is round-tripping — empty objects and arrays are preserved rather than silently vanishing, and null is kept as the value it is. Drop those and the result cannot be reversed, which quietly defeats the point. Everything happens in your browser.

How each shape flattens

InputFlattened
{"a":{"b":1}}{"a.b": 1}
{"a":[1,2]}{"a.0": 1, "a.1": 2}
{"a":[{"b":1}]}{"a.0.b": 1}
{"a":{}}{"a": {}} — kept, so it round-trips
{"a":null}{"a": null} — null is a value
[1,2]{"0": 1, "1": 2}

When to use it

  1. Turn a nested config into flat environment-variable style keys.
  2. Prepare JSON for a spreadsheet, where each key becomes a column.
  3. Map an API response onto flat form field names.
  4. Rebuild nested JSON from flat keys you were given.
  5. Compare two documents more easily by flattening both first.

How to Use

  1. Paste your JSON.
  2. Pick a separator and whether arrays use brackets.
  3. Copy the flattened result, or switch on unflatten to go the other way.

Features

  1. Flatten and unflatten, both directions
  2. Exact round-tripping, including empty objects and arrays
  3. Dot or bracket notation for array indices
  4. Custom separator for keys that already contain dots
  5. Null preserved as a value, not skipped
  6. 100% client-side

FAQs

Is my JSON uploaded?

No. Everything runs in your browser and nothing is transmitted.

Can I get the nested JSON back?

Yes — switch on 'Unflatten instead' and paste the flat keys. The two directions round-trip exactly, including empty objects and arrays, which many flatteners drop and thereby make the operation one-way.

Why do empty objects matter?

Because an empty object has no leaf inside it, so a naive flattener emits nothing for it and the key disappears. Unflatten that result and the key is simply gone — a silent change to your data. Keeping them as values avoids that.

Should I use a.0 or a[0] for arrays?

Depends on the consumer. Bracket notation is what most form libraries and many config systems expect; dot notation is simpler and common in flat key-value stores. Both round-trip here.

What if my keys already contain a dot?

Change the separator to something that does not appear in your keys — a pipe or a double colon, for instance. Otherwise unflattening will split in the wrong place, because it cannot tell your dot from a level boundary.

Technical Details

Flattening walks the document and joins the keys along each route into a single dot-notation key, with array indices becoming either `a.0` or `a[0]` depending on the notation chosen, since config systems and form libraries disagree about which they expect. The detail most flatteners get wrong is empty containers: an empty object or array has no leaf beneath it, so a naive recursion emits nothing and the key disappears entirely. That makes the operation irreversible, and a flattener you cannot reverse is of limited use — so empty objects and arrays are kept as values in their own right. Null is likewise preserved rather than skipped, because null is a value and its absence means something different. Unflattening splits each key back into segments and decides array versus object by looking at the NEXT segment: a run of digits creates an array, anything else an object, which is exactly the convention flattening writes and is what makes the pair round-trip. The top level is returned as an array when every root key is an index, so a flattened array comes back as an array rather than as an object with numeric keys. Both directions are available in one place because the reverse is needed as often as the forward: flattened keys are how environment variables, spreadsheet columns and form field names represent nesting, and turning those back into real JSON is the other half of the job. Everything runs in your browser.

Developer Tools

Developer Tools

  • JSON Diff Checker
  • JSONPath Extractor
  • JSON Schema Generator
  • License Generator
  • Nanoid Generator
  • Random String Generator
  • Test IBAN Generator
  • UUID Generator