Trexmi
Converter Ready

JSON Flatten

Flatten nested JSON objects and arrays into reversible $-rooted path-value pairs while preserving empty objects, empty arrays, scalar types, and array indexes.

Flatten objects into dot or slash paths Represent arrays with zero-based bracket indexes Preserve empty objects and arrays Escape separators and brackets inside property names
Backslash escapes separators and brackets inside object keys. Arrays always use zero-based [index] notation.
INPUT Nested JSON *
0 chars0 words0 lines
Objects become escaped path segments, arrays use [index], and the root is $. Empty objects and arrays are preserved. Example: Trexmi developer sample

Tool settings

Ctrl / ⌘ + Enter
Flattened JSON path map Every value and empty container is mapped to a reversible $-rooted path.
About the tool

What JSON Flatten does

JSON Flatten converts a nested JSON document into a flat JSON object whose property names describe the original location of every value. All paths begin with $. Object properties use the selected dot or slash separator, while arrays use explicit indexes such as [0].

The output is designed to be reversible with Trexmi JSON Unflatten. Empty objects and arrays are kept as values instead of disappearing. A backslash escapes a separator or bracket that belongs to an actual property name. This path syntax is a Trexmi interchange convention, not JSONPath or JSON Pointer.

JSON Flatten converting nested objects and arrays into reversible paths
Turn nested JSON into explicit typed paths without losing empty containers.

How to use

  1. Paste nested JSON. Use a complete object, array, or scalar that parses under standard JSON rules.
  2. Select a separator. Dot mode produces paths such as $.order.id; slash mode produces $/order/id.
  3. Flatten the document. Array locations remain visible as [0], [1], and later indexes.
  4. Inspect special keys. Property separators, brackets, and backslashes are escaped so they are not mistaken for path syntax.
  5. Verify the round trip. Run the flat result through JSON Unflatten with the same separator before relying on it in an import or migration.
Built for the task

Why use JSON Flatten?

Focused controls, predictable output, and a workflow designed around this exact transformation.

01

Reversible paths

Use one explicit root marker and distinct object and array notation for reliable reconstruction.

02

Empty values retained

Preserve empty objects, empty arrays, null, booleans, numbers, and strings.

03

Escaped property names

Keep keys that contain dots, slashes, brackets, or backslashes without path ambiguity.

04

Readable field map

Inspect deeply nested payloads as a compact list of locations and typed values.

Useful answers

Questions about JSON Flatten

Practical details about input, output, privacy, limits, and the best way to use this tool.

01 What does JSON Flatten output?

It outputs one JSON object. Each property name is a $-rooted path and each property value is the JSON value stored at that location.

02 How are arrays represented?

Arrays use zero-based bracket indexes. For example, the first item name is represented as $.items[0].name in dot mode.

03 Are empty objects and arrays preserved?

Yes. An empty container is stored directly at its path so JSON Unflatten can recreate it.

04 What if a property name contains a dot or slash?

The selected separator is escaped with a backslash. Brackets and backslashes inside property names are escaped as well.

05 Is this output standard JSONPath?

No. It resembles familiar path notation but is a reversible Trexmi flat-map format. Do not pass these keys directly to a JSONPath engine.

06 Can the root value be an array or scalar?

Yes. A root array begins with paths such as $[0]. A root scalar or empty root container is stored under the exact $ path.

07 Will flattening preserve object key order?

The generated map follows the parsed source order, but JSON object member order should not be used as application logic. Array order is preserved by indexes.

08 Can JSON Flatten replace an ETL mapping?

No. It exposes paths and values but does not rename fields, join datasets, validate a business schema, or guarantee compatibility with a destination database.

Learn JSON

Read the complete JSON Guide

Learn JSON objects, arrays, value types, validation, formatting, parsing, API workflows, and common syntax errors.

  • Objects, arrays, and values
  • Validation and formatting
  • API and parsing workflows
Read guide Practical explanations and examples

Examples

Flatten a nested order

Object properties become dot-separated paths and each JSON scalar keeps its type.

Input
{"order":{"id":1042,"customer":{"name":"Ada"},"paid":true}}
Output
{"$.order.id":1042,"$.order.customer.name":"Ada","$.order.paid":true}

Flatten an array of items

Bracket indexes preserve array order separately from object property names.

Input
{"items":[{"sku":"A-1","qty":2},{"sku":"B-7","qty":1}]}
Output
{"$.items[0].sku":"A-1","$.items[0].qty":2,"$.items[1].sku":"B-7","$.items[1].qty":1}

Preserve empty containers

Empty objects and arrays are leaves because otherwise their existence would be lost.

Input
{"filters":{},"results":[],"next":null}
Output
{"$.filters":{},"$.results":[],"$.next":null}

Escape a dot inside a key

The doubled JSON backslash represents one path escape: the first dot is data and the next dot is the object separator.

Input
{"release.version":{"major":2}}
Output
{"$.release\\.version.major":2}

How the flat path model works

The root marker is $. In dot mode, an object property is appended as .property; in slash mode it is appended as /property. An array position is always appended as [index]. Keeping array notation independent from the object separator lets the reverse operation distinguish an object property named 0 from array index zero.

The flat output remains valid JSON. Values are not converted to display strings: true remains a boolean, null remains null, and numbers remain JSON numbers as supported by the server parser.

Arrays, empty containers, and root values

A normal leaf is a string, number, boolean, or null. Empty objects and arrays are also treated as leaves because there are no children from which JSON Unflatten could infer their existence. Non-empty arrays create one path for every indexed descendant.

Use JSON Unflatten with the same separator to test reversibility. Use JSON Formatter first when the input is hard to read, or JSON Path Finder when the goal is searching rather than transformation.

Property names that contain path characters

A property separator, opening or closing bracket, or literal backslash is escaped with a preceding backslash. For example, the key release.version becomes release\.version in dot mode. The escape belongs to the flat path only; the original key is restored without it.

Do not edit escaped paths casually. Removing one backslash can change a single property name into two nested properties.

Limitations and edge cases

Flattening is a structural transformation, not schema validation. It cannot determine required fields, normalize dates, resolve references, detect duplicate object member names already collapsed by a JSON parser, or map values to SQL columns. Very deep or very large documents remain subject to server input and JSON nesting limits.

JSON itself defines objects, arrays, numbers, strings, booleans, and null, but it does not define a universal flattening syntax. Read RFC 8259 for JSON interoperability rules. For a standardized single-location syntax with different escaping rules, compare JSON Pointer RFC 6901.

Related workflow

After verifying the flat map, reconstruct it with JSON Unflatten or export suitable records through JSON to CSV.