dot-path · 2-way · arrays preserved

Flatten nested JSON to dot-paths

Turn nested structures into a single-level object with dot, slash, or underscore separators. Round-trip back to nested with one click.

Flatten / Unflatten JSON
Input size
125 B
7 lines
Output size
143 B
5 keys
Mode
flatten
sep "."
Status
Valid
dot-path / slash / underscore
Mode
Sep
input · nested
output · flat
{
  "user.name": "Ada",
  "user.address.city": "London",
  "user.address.country": "UK",
  "user.tags.0": "admin",
  "user.tags.1": "founder"
}
Quick Start

How to flatten and unflatten JSON

Flatten turns {"a":{"b":1}} into {"a.b":1} — convenient for spreadsheets, env vars, or feature flag stores. Unflatten reverses it cleanly.

  1. 01

    Paste nested JSON (or flat)

    Drop in either shape — toggle Flatten or Unflatten depending on direction.

    Inputs parse through the native JSON.parse reviver chain — strict RFC 8259. Any syntax error returns line and column for the exact offending byte.

    nestedflatRFC 8259JSON.parsestrict
    input · raw.json · RFC 8259
    {"a":{"b":1}}
    loaded · parsed RFC 8259RFC 8259 · ready
  2. 02

    Pick separator

    Dot (default), slash, or underscore. Useful when downstream tooling reserves certain characters.

    Indent options run through JSON.stringify(value, null, n); the second argument lets you sort, transform, or omit keys via a replacer if you ever wire one in.

    . / _indentJSON.stringifyliveordered
    separator · optionsdot · live
    {"a.b": 1}
    options applied · livelive
  3. 03

    Arrays kept

    Arrays flatten with numeric indexes: tags.0, tags.1. Round-trip is lossless.

    Large documents stream through a useMemo with stable hashing so options re-apply instantly — no full re-parse if only formatting changes.

    arraysindexmemoisedinstantdiff-friendly
    arrays · renderedindexes · ready
    {"tags.0":"a","tags.1":"b"}
    rendered · livediff-friendly
  4. 04

    Copy or download

    Swap mode sends the output back as input — handy for verifying round-trip equivalence.

    Download is a Blob with application/json; copy uses the Async Clipboard API. Both round-trip identically to what the page rendered.

    round-tripverifyclipboardblob.json
    export · copiedready · done
    ✓ Copied
    shipped · ready to shipsuccess
Pro tips

Production-grade JSON, the right way

Stick to RFC 8259

Strict JSON has no NaN, Infinity, comments, or trailing commas. If you need those, look at JSON5 or JSON Repair.

Preserve key order for diffs

JavaScript preserves insertion order, but two parsers shouldn’t be assumed equal. Use Sort JSON Keys before diffing or hashing.

Big integers lose precision

JS numbers lose precision past 2^53−1. Transport large IDs as strings or use BigInt.

Escape inside HTML

When inlining JSON inside <script>, escape </ to <\/ so HTML parsing doesn’t close your tag early.

Validate at boundaries

Trust the wire as little as possible. Run incoming JSON through a schema (Zod / Pydantic) before it touches business logic.

Minify in production

Minify removes whitespace; gzip removes redundancy. Together they typically shrink JSON payloads 70–85% over the wire.

Use Cases

When to flatten JSON

Anywhere downstream tooling expects flat key-value pairs.

Spreadsheet export

Flatten before piping to JSON to CSV for one column per leaf. Output round-trips losslessly through JSON.parse + JSON.stringify, so the file you save is byte-identical to what you see. Streaming parsers, jq pipelines, and Postgres jsonb columns all accept the result without complaint.

10× faster to scan

Feature flag stores

LaunchDarkly, ConfigCat, Flagsmith expect flat paths. Pairs perfectly with sort-keys + diff for review-friendly fixtures in CI. Whitespace-only churn disappears and reviewers see real changes, which keeps PR comments focused on logic rather than indentation.

cleaner PR diffs

env vars

Some env-var systems use APP_DB_HOST with underscores — flatten with _ as separator.

RFC 8259 valid

Analytics

Some analytics platforms expect flat event payloads. Re-parses on every keystroke so syntax errors are caught at the exact character. Strict RFC 8259 — no trailing commas, no comments, no unquoted keys — keeps downstream parsers happy.

round-trip safe

i18n keys

Flatten translations to dot-keyed strings for translator workflows. Streams large documents without a server round-trip — privacy stays in the tab. Heavy parsing runs through useMemo so even 5 MB payloads keep the editor responsive.

i18n-friendly

Reverse: unflatten

Take a flat property file and rebuild nested config. Output is byte-stable: same input plus same options always produces identical bytes, ideal for content-addressed caches and snapshot tests. Downloads ship with the application/json MIME so editors apply syntax highlighting.

production-ready
FAQ

Frequently asked questions

Dot, slash, or underscore. Pick whichever your downstream tool prefers.
Yes — they flatten to numeric indexes (tags.0, tags.1) and unflatten back to arrays.
For plain objects and arrays with primitive leaves, yes. Keys that contain the separator might collide — pick a separator your data doesn't use.
Yes. The tool re-builds arrays when consecutive segments are numeric, otherwise objects.
No. All processing runs locally.
Suggest a tool

Something missing?

Tell us what you need. We ship the top requests every two weeks.

Sent straight to the maintainers · no account needed
47 in queue·8 shipped this month
Request queued. Thanks!