Skip to main content
NyankoTools

JSON Key Sorter & Flatten / Unflatten

Sort the keys of a JSON document, flatten nested data into single-level a.b[0] paths, or rebuild the original structure. Handy for normalizing JSON before a comparison. For plain pretty-printing use the JSON Formatter; to see what changed, try the JSON Diff.

🔒 Runs in your browser · Your data is never sent to a server

How to use

  1. Choose sort, flatten or unflatten in "Mode".
  2. For sorting, pick the order and whether to recurse, then paste your JSON into "Input".
  3. The converted JSON appears in "Result"; take it with "Copy".

Notes

  • Numbers are written exactly as typed, so long integers such as 12345678901234567890 are not rounded.
  • Keys are ordered by UTF-16 code units, so 10 comes before 2. The order of array elements is never changed.
  • When flattening, keys containing dots, brackets or spaces, and digit-only keys, use bracket notation with a JSON-quoted key. When unflattening, a quoted key in brackets is always an object key and bare digits in brackets, like [0], are an array index (a.0 means the object key 0).
  • Empty arrays [] and empty objects {} stay as values. A scalar or empty root is returned unchanged.
  • Skipped array indexes are filled with null when unflattening (maximum index 100000). If a key is duplicated, the last value wins.
  • Your JSON is processed in the browser and is never sent to a server.

Glossary

Flatten

Converting nested JSON into a single-level object whose keys are paths such as a.b[0]. Common before exporting to env vars, translation files or CSV.

Unflatten

The reverse of flattening: parsing keys like a.b[0] and rebuilding the original nested structure.

Prototype pollution

An attack that abuses special keys such as __proto__ to alter shared object behavior. This tool builds results with Map, so it is not affected.

FAQ

Does sorting keys change the order of arrays?

No. Only object keys are sorted; the order of array elements is always preserved. With recursion on, objects inside arrays still get their keys sorted.

What happens to keys that contain a dot when flattening?

Keys with dots, brackets or spaces, empty keys and digit-only keys are written in bracket form such as ["a.b"], and unflattening restores the original key. a.b and ["a.b"] are kept distinct.

Are long integers rounded?

No. Numbers are written exactly as they appear in the input. Be aware, though, that JavaScript and some other programs round integers beyond 15 to 17 digits when they read the result.

Why does unflatten report a conflict?

It happens when a location is both a value and a parent, as with "a": 1 and "a.b": 2, or when array and object are mixed, as with "a[0]" and "a.b". These cannot be rebuilt unambiguously.

Share this page

↑↓ Select Enter Open Esc Close