Skip to content
4all.tools

Flatten and Reconstruct JSON Paths in Your Browser

Turn nested JSON into a map of paths and values, or rebuild the original structure from a map. Process files locally in your browser.

Tool workspace

JSON Flatten and Unflatten

Enable JavaScript to process JSON locally in your browser.

Operation

The root is $. A simple property can be written as $.name; a literal key with a dot uses $["a.b"]; an array index uses $[0]. The empty flat map {} is invalid; {"$":{}} represents an empty object. Conflicts can occur when one path is also a prefix of another, such as {"$.a":1,"$.a.b":2}. Sparse arrays are rejected, for example {"$[2]":"x"}. Not every dotted-key map can be reconstructed unambiguously. The inverse operation checks the limits again.

Using a result switches to the inverse operation. Its limits are checked again; it does not run automatically.

File: 8,000,000 bytes; input: 2,000,000 UTF-16 units; depth: 200; nodes: 100,000; entries: 50,000; output: 2,000,000 UTF-16 units.

Processing work limits

Work caps: 1,000,000 parse units, 1,000,000 transform units, and 1,000,000 serialization units. Paths allow 200 segments, 10,000 units each, and 1,000,000 units total; array indices are at most 99,999. These maxima cannot all be guaranteed simultaneously.

Processing stays in this browser. No uploads, remote URLs, saved drafts, or document content in URLs or logs.

No file selected

Example input

Load the example for the selected operation.

{"user":{"name":"Ana"},"items":[1,{},[]],"a.b":null,"":true}
Path syntax examples

{"$.user.name":"Ana","$.items[0]":1,"$.items[1]":{},"$.items[2]":[],"$[\"a.b\"]":null,"$[\"\"]":true}

{"$[\"user\"][\"name\"]":"Ana","$[\"items\"][0]":1,"$[\"items\"][1]":{},"$[\"items\"][2]":[],"$[\"a.b\"]":null,"$[\"\"]":true}

Formatting options

Ready. Choose an operation and run it to process the current input.

    Turn nested JSON into a path map

    Flattening gives each value its own path. This helps when you need to inspect a deeply nested document or work with values by their location. Paste JSON or open a local UTF-8 .json file, choose Flatten JSON, then run the operation. To reverse it, paste a path map and choose Reconstruct JSON.

    Try this document:

    {"user":{"name":"Ana"},"items":[1,{},[]],"a.b":null,"":true}

    Using dot notation:

    {"$.user.name":"Ana","$.items[0]":1,"$.items[1]":{},"$.items[2]":[],"$[\"a.b\"]":null,"$[\"\"]":true}

    Using bracket notation:

    {"$[\"user\"][\"name\"]":"Ana","$[\"items\"][0]":1,"$[\"items\"][1]":{},"$[\"items\"][2]":[],"$[\"a.b\"]":null,"$[\"\"]":true}

    Both maps reconstruct the input data. The default output uses two spaces; examples are minified so the path spelling is easy to compare.

    How to read the paths

    $ is the root. $.name points to the property name, while $[0] points to the first array element. Quotes matter: $["0"] is a property named 0, not an array index. A key containing a dot, such as a.b, is written as $["a.b"] so the dot stays part of its name.

    Dot notation uses brackets when a key needs them; bracket notation uses them for every property. Reconstruction accepts either style or a mixture. These paths do not support JSONPath filters, wildcards or slices.

    The map is a non-empty JSON object. Its values are primitives or empty containers; the paths supply the structure around them. Empty objects and arrays are preserved: {"$.settings":{},"$.items":[]} reconstructs both. A primitive or empty root uses one entry, such as {"$":null}. An empty map {} cannot identify a root value.

    Conflicting paths are rejected. For example, {"$.a":1,"$.a.b":2} asks a to be both a number and an object. {"$.a":1,"$[0]":2} mixes an object and an array at the root. Array indices must start at zero without gaps, so {"$[2]":"x"} is also invalid. Duplicate paths, including two spellings of the same path, are rejected instead of overwriting values.

    Numbers and the return trip

    The input must be strict JSON. Comments, JSONC, JSON5 and duplicate keys are rejected. This includes keys that become identical after decoding, as in {"a":1,"\u0061":2}.

    Numbers keep their original spelling: 9007199254740993, 0.10000000000000001, -0 and 1E+02 are not rewritten. A precision warning concerns their internal JavaScript representation; it does not mean the output was rounded. Numbers outside the supported range, such as 1e400, are rejected.

    Flattening and reconstructing preserves values, keys, array positions and number spelling within the tool’s limits. Formatting, escape spelling and object property order may change. The result uses LF line endings without a BOM or final newline.

    Copy the complete result

    The preview shows up to 20,000 UTF-16 units and may end in the middle of the JSON. Copy JSON and Download JSON include the complete result. If the clipboard is unavailable, use the manual-copy field. Downloads are UTF-8 files named json-flattened.json or json-reconstructed.json.

    Use result as input puts the complete output in the editor and switches to the reverse operation. Run it when you are ready. Editing the input or options clears the previous result; canceling keeps your input.

    Limit Maximum
    Local file 8,000,000 bytes
    Input or output text 2,000,000 UTF-16 units
    Nested containers / path segments 200
    JSON values 100,000
    Map entries 50,000
    Single path 10,000 UTF-16 units
    Array index 99,999
    Operation time 15 seconds

    Complex documents can reach processing limits before the size limits. Processing stays in your browser; documents are not uploaded or saved.