Developer Formatting

JSON flattener

What to do

Processed in your browser · nothing is uploaded

Local · empty containers survive the round trip
Advertisement
320 × 100

Turns a nested structure into a single object keyed by dotted path; `user.name`, `user.tags[0]`, and turns it back again.

How to use the json flattener

1 Paste the nested JSON and read the dotted paths.
2 Switch to Unflatten to rebuild the nesting from a flat object.
3 Check for keys that already contain a dot before relying on the round trip.
4 Copy the result, or save it as a file.

Flattened JSON is what a lot of systems actually want: translation files, feature-flag stores, environment configuration and analytics payloads are all flat key-value maps, and a nested document has to be flattened to fit. The notation is the one those systems already use — dots between object keys, square brackets around array positions, so user.tags[0] reads back unambiguously.

Empty arrays and objects have no leaf to flatten into, and they are kept as explicit empty values rather than dropped. That is what makes the round trip work: a tags: [] that vanished on the way out would come back as "no such field", which is a different statement about the data.

Two shapes break the round trip, and both involve a key that looks like something else. A key that already contains a dot; {"a.b": 1}. Is indistinguishable from nesting once flattened, and comes back nested. Worse, a numeric object key becomes an array index: {"counts": {"1": 5}} flattens to counts.1 and unflattens to {"counts": [null, 5]}, because a numeric path segment can only be read as a position. If your keys are years, IDs or numeric codes, dotted notation is the wrong tool for them.

Flattening is also not the way to get JSON into a spreadsheet, though it looks close. It produces one object with many keys, not rows and columns: the JSON to CSV tool does that job properly, header row included.

Questions

Dots for object keys and square brackets for array indices, so `a.b[0].c`. That is the convention most config systems use.

ECMA-404; the JSON data interchange syntaxMDN, JSON.parse()
Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding