Skip to content
gohacks.dev
Standard Library

Flatten JSON to Dot Notation

Flatten nested JSON into one level of dot.path keys, or unflatten dot-notation keys back into nested objects and arrays.

Free · No sign-up · Your inputs stay in your browser

Input

Flatten nested JSON to dot paths, or back

Output

Flat object

14 keys

Dot paths are what Laravel's Arr::dot() and data_get() use, and what most translation files and config stores expect. Empty objects and arrays are kept as values so a round trip loses nothing.

Runs in this browser. Nothing you paste is sent to a server.

Where dot paths are used

Laravel's Arr::dot(), data_get() and validation rules address nested data with dot paths, and so do translation files, feature-flag services, spreadsheet exports and most key-value config stores. Flattening is also the quickest way to diff two large JSON documents line by line, because every value ends up on its own line with its full path.

Brackets or dots for arrays

Some tools write array indexes as items[0].id (lodash's _.get, JavaScript itself) and others as items.0.id (Laravel, MongoDB). Both forms are read back when unflattening. Keys that already contain the separator are ambiguous, so pick a separator that does not appear in your keys.

Share

Frequently asked questions

What is the difference between flattening and serialising JSON?
Serialising turns a whole structure into one string. Flattening keeps it as JSON but moves every value to the top level under a key that records its path, so it can be stored in a flat key-value system and rebuilt later.
Does unflattening restore arrays?
Yes. A path segment that is a whole number, such as orders.0.total or orders[0].total, creates an array at that level instead of an object.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools