Home › Developer Tools › JSON Flatten / Unflatten

JSON Flatten / Unflatten

Turn deeply nested JSON into a single-level object with path keys like user.address.city or orders[0].sku, or rebuild nested JSON from flat keys. Choose the separator and array style; numbers and key order are preserved exactly.

Last updated:

Everything runs in this tab: your JSON is never uploaded. Big numbers and key order are kept exactly. Tip: Ctrl + Enter runs.

Advertisement
Advertisement

How to use the JSON Flatten / Unflatten

  1. Choose Flatten or Unflatten with the tabs at the top. A sample is loaded so you can see the result right away.
  2. Paste your JSON or open a .json file. In Unflatten mode, paste an object whose keys are paths, such as {"user.name": "Ada"}.
  3. Set the separator and array style: dot, underscore or slash, and items.0 or items[0] for array indexes.
  4. Adjust the extras: levels to flatten, keeping empty {} and [], sorting keys, or numeric keys creating arrays.
  5. Copy or download the result, or press Swap to feed it back in and check the round trip.

Flatten and unflatten example

Nested JSON on the left, the flattened version with the default dot separator on the right. Unflatten turns the right side back into the left side exactly.

Nested JSONFlat JSON
{
  "user": {
    "name": "Ada",
    "address": { "city": "London" }
  },
  "tags": ["math", "poetry"],
  "meta": {}
}
{
  "user.name": "Ada",
  "user.address.city": "London",
  "tags.0": "math",
  "tags.1": "poetry",
  "meta": {}
}

Separator and array styles

Different tools expect different path formats. Pick the one your destination understands:

SettingPath for the city of the first orderTypical use
Separator ., separator indexesorders.0.address.cityMongoDB dot notation, Elasticsearch fields, i18n files, lodash get
Separator ., bracket indexesorders[0].address.cityJavaScript property paths, form field names, jq-style paths
Separator _orders_0_address_cityCSV and spreadsheet column headers, SQL column names
Separator __orders__0__address__cityEnvironment variables (for example ASP.NET Core configuration)
Separator /orders/0/address/cityPaths similar to JSON Pointer (RFC 6901) and file-like keys

Tips for a lossless round trip

  • Keep empty objects and arrays. An empty {} or [] has no values to produce a path, so without this option it disappears when you flatten.
  • Choose a separator that is not in your keys. If a key such as "file.name" contains the separator, unflattening splits it into two levels. The tool warns you when this happens.
  • Numeric object keys. Keys such as "2024" or user IDs look like array indexes. Turn off Numeric keys create arrays when unflattening so they stay object keys.
  • Arrays with gaps. If a flat object has items.0 and items.3, the missing positions 1 and 2 are filled with null, because JSON arrays cannot have holes.

Frequently asked questions

What does flattening JSON mean?

Flattening turns a nested JSON structure into an object with only one level. Each key becomes the full path to a value, joined with a separator, so {"user": {"name": "Ada"}} becomes {"user.name": "Ada"}. Flat JSON is easier to load into spreadsheets, CSV files, search indexes, environment variables and translation (i18n) tools.

How are arrays flattened?

Each array item gets its index in the path. With the separator style, the second tag of a user becomes user.tags.1; with the bracket style it becomes user.tags[1], the notation used by JavaScript and many query languages. Unflatten understands both styles.

How does unflatten decide between objects and arrays?

When 'Numeric keys create arrays' is on, a path segment that is a whole number such as 0 or 12 creates an array, and bracket indexes like [0] always do. Missing indexes are filled with null. Turn the option off if your objects use numeric keys, such as IDs, that should stay object keys.

What happens if a key already contains the separator?

A key like "file.name" flattens to a path that looks like two levels, so unflattening would split it into file → name. The tool warns you when this happens; pick a separator that does not appear in your keys, such as / or __, to get a lossless round trip.

What are conflicting keys when unflattening?

A conflict happens when one key uses a path as a value and another uses it as a parent, for example "a": 1 together with "a.b": 2. A value cannot be both a number and an object, so the second key is skipped and listed in the message.

Are large numbers kept exactly?

Yes. The tool uses its own JSON parser that keeps every number exactly as written, so IDs larger than 9,007,199,254,740,991 (2^53 − 1) are not rounded as they would be by JavaScript's JSON.parse. Key order is also preserved.

Is my JSON uploaded anywhere?

No. Flattening and unflattening run entirely in JavaScript in this page, so your data never leaves your device.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.JSON to CSVConvert JSON data to CSV for spreadsheets.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.JSON SorterSort JSON keys A-Z recursively, sort arrays by value or by a key, then pretty-print or minify.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.JSON to Go StructTurn JSON into Go structs with inferred types, nested structs and json tags.JSON to Python ClassGenerate Python dataclasses, Pydantic models or TypedDicts with type hints from JSON.Query String to JSONConvert URL query strings to JSON with nested brackets and arrays, and JSON back to a query string.REM to PX ConverterConvert CSS rem values to pixels for any root font size, with a quick 0.25–6rem table.SQL to JSON ConverterConvert SQL INSERT statements and dumps into a JSON array of row objects, with CSV export.TSV to CSV ConverterConvert TSV to CSV and back, or between tab, comma, semicolon and pipe, with correct quoting.TypeScript to JavaScriptConvert TypeScript or TSX to clean JavaScript instantly: strip types, keep or compile JSX.XML to YAML ConverterConvert XML to clean YAML with attributes, text nodes, lists and exact error lines.YAML to XML ConverterConvert YAML to pretty, well-formed XML with custom root, attributes and array item tags.Boolean Algebra SimplifierSimplify boolean expressions or minterm lists to minimal SOP and POS with Quine-McCluskey steps.Compare Excel FilesCompare two Excel spreadsheets cell by cell, highlight changes and export a diff report.CSV CleanerClean messy CSV in one click: trim spaces, drop empty rows and columns, fix headers, dedupe.CSV VLOOKUP ToolJoin two CSV or Excel files on a key column like VLOOKUP, with left, inner and full joins.Remove Duplicates in ExcelFind and remove or highlight duplicate rows in XLSX or CSV files by the columns you choose.GeoJSON ViewerView GeoJSON on a map, inspect and edit properties, validate against RFC 7946 and export.GPX ViewerOpen GPX tracks on a map with distance, elevation profile, moving time, speed and splits.JSON Repair ToolFix broken JSON automatically: trailing commas, quotes, comments, truncated data, with a diff.Karnaugh Map SolverSolve 2–6 variable K-maps: click cells or enter minterms to get the minimal SOP or POS with groups.Merge Excel FilesCombine XLSX, XLS and CSV files into one workbook or append all rows into a single sheet.Parquet File ViewerOpen Apache Parquet files in your browser: schema, rows, filters and CSV or JSON export.Query CSV with SQLRun SQL on CSV, Excel, JSON and Parquet files in your browser with DuckDB. Join and export.Online Serial MonitorTalk to Arduino, ESP32 and USB serial devices in your browser: log, send, plot and save.Split Excel FileSplit an Excel sheet into several files by row count or by each value in a column, as ZIP.SQL Create Table GeneratorDefine columns, keys, defaults and indexes; get CREATE TABLE SQL for MySQL, Postgres and more.SQL IN Clause GeneratorTurn a pasted list into a SQL IN ('a','b') clause with quoting, dedupe and 1,000-item chunks.SQL Online CompilerRun SQL queries online on SQLite with sample databases, a result grid, CSV export and .db save.SQL to ER DiagramPaste CREATE TABLE statements and get an entity-relationship diagram with keys and links.XML to XSD GeneratorGenerate an XML Schema (XSD) from sample XML: types, occurrences, attributes and namespaces.XML ValidatorCheck if XML is well-formed, see the exact line and column of each error and pretty-print it.Wildcard Mask CalculatorConvert a subnet mask or CIDR to a wildcard mask for ACLs and OSPF, with range and binary.CSV to VCF ConverterConvert a contacts CSV into a vCard (.vcf) file, mapping columns to name, phone, email and more.CSV to YAML ConverterConvert CSV rows to a YAML list of mappings with type inference and delimiter detection.
See all 129 Data & File Format Converters →