Try the online flattener instantly or copy JavaScript / Python examples below.

JSON Flatten & Unflatten

FreePrivateConfigurable separator

Flatten nested JSON into path-based keys instantly using the tool below. Also learn how to flatten nested objects in JavaScript and Python with ready-to-use code examples on this page.

  • Instant online flattening
  • JavaScript example included
  • Python example included
  • No upload required

Turn nested objects into path-based keys.

Path Separator
Previewuser.name
Nested JSON

Paste JSON input and run conversion.

Output
Ctrl+Enter Run

Flatten Nested JSON Online

Flatten nested JSON objects instantly with the online tool below. Convert deep structures into dot-path keys, then explore ready-to-use JavaScript and Python code examples for your own projects.

  • Instant online flattening
  • JavaScript example included
  • Python example included
  • No upload required

Example

Input
{
  "user": {
    "name": "Alice",
    "address": {
      "city": "London"
    }
  }
}
Output
{
  "user.name": "Alice",
  "user.address.city": "London"
}

Need results instantly? Use the live flattener above: paste JSON, choose a separator, then click Flatten.

Code examples

Use this function to flatten nested objects in JavaScript (recursive walk, configurable separator, arrays indexed as 0, 1, …).

Use this function to flatten nested dictionaries in Python (same idea: dicts recurse, lists use numeric segments).

JavaScript
/** * Recursively flatten a plain object into path-based keys. * Arrays use numeric segments: items.0, items.1, … */ function flattenNestedObject(input, parentKey = '', separator = '.') { const out = {}; for (const [key, value] of Object.entries(input)) { const path = parentKey ? `${parentKey}${separator}${key}` : key; if (value !== null && typeof value === 'object' && !Array.isArray(value)) { Object.assign(out, flattenNestedObject(value, path, separator)); } else if (Array.isArray(value)) { value.forEach((item, index) => { const ix = `${path}${separator}${index}`; if (item !== null && typeof item === 'object' && !Array.isArray(item)) { Object.assign(out, flattenNestedObject(item, ix, separator)); } else { out[ix] = item; } }); } else { out[path] = value; } } return out; } const nested = { user: { name: 'Alice', address: { city: 'London' }, }, }; console.log(flattenNestedObject(nested)); // → { 'user.name': 'Alice', 'user.address.city': 'London' }

Want to test with your own data? Open JSON Flatten Tool: same engine, dedicated workflow page.

Features

  • Instant online flattening
  • JavaScript code example
  • Python code example
  • Configurable separators
  • Browser-only private processing
  • Mobile friendly

How to use the tool

  1. Keep mode on Flatten (default).
  2. Pick a path separator: dot, underscore, or slash.
  3. Paste nested JSON into the input panel.
  4. Click Flatten or press Ctrl+Enter.
  5. Copy or download the flat result. Switch to Unflatten anytime to reverse.

Frequently asked questions

What does flatten nested JSON mean?

It turns nested objects into one level of keys, encoding the path with a separator: for example user.address.city instead of nested address objects.

Is this tool free?

Yes. No sign-up required.

Is my data uploaded?

No. Flattening runs locally in your browser.

Can I unflatten later?

Yes. Use Unflatten on this tool with the same separator you used when flattening, or visit JSON Flatten.

How do I flatten JSON in JavaScript?

Walk objects and arrays recursively and join key segments: see the JavaScript tab above. The live tool uses the same path rules as our on-site flatten engine.

Is Python code included?

Yes. Open the Python tab for a recursive dict example with separator support.

Does it work on mobile?

Yes. Mode controls, separators, and code tabs are sized for touch; code blocks scroll horizontally when needed.

Can I change separators?

Yes. Choose dot, underscore, or slash in the tool: match that choice if you port the logic to JavaScript or Python.

Related tools