Flatten JSON Object
Convert nested JSON objects into a single-level structure with dot-notation keys.
Input (JSON Object)
Options
Output (Flattened Object)
What It Does
The Flatten JSON Object tool transforms deeply nested JSON structures into a single-level object using dot notation for keys. Whether your JSON has two levels of nesting or ten, this tool recursively traverses every branch and produces a clean, flat representation where each key encodes the full path to its value. For example, a nested structure like `{"user":{"address":{"city":"London"}}}` becomes `{"user.address.city":"London"}` — instantly readable, queryable, and portable. This tool is invaluable for developers, data engineers, and analysts who work across systems that don't natively support nested data. Many relational databases, CSV exports, environment variable systems, and configuration frameworks require flat key-value pairs. Rather than manually unwinding nested objects — a tedious and error-prone process — you can paste your JSON and get a flattened result in seconds. Arrays are handled gracefully using index notation, so `{"items":["a","b"]}` becomes `{"items.0":"a","items.1":"b"}`. All original values are preserved exactly, including strings, numbers, booleans, and nulls. The output is always valid JSON, ready to copy into your codebase, database insert, config file, or downstream pipeline. Whether you're debugging a deeply nested API response, preparing data for Elasticsearch, or standardizing configs across environments, this tool saves meaningful time.
How It Works
The Flatten JSON Object applies its selected transformation logic to your input and produces output based on the options you choose.
It applies a fixed set of transformation rules to your input, so the output is stable and easy to verify.
All processing happens in your browser, so your input stays on your device during the transformation.
Common Use Cases
- Flattening nested API response payloads before inserting records into a relational database that expects flat column structures.
- Converting deeply nested configuration objects into flat key-value pairs for use in environment variable systems like dotenv or AWS Parameter Store.
- Preparing complex JSON documents for indexing in Elasticsearch or OpenSearch, which benefits from flattened field paths for efficient querying.
- Simplifying nested Redux state or application config objects during debugging to quickly inspect all values at a glance.
- Transforming nested JSON exported from MongoDB or Firebase into flat rows compatible with spreadsheet tools like Excel or Google Sheets.
- Normalizing inconsistently nested third-party API responses before feeding them into a data pipeline or ETL process.
- Converting nested i18n translation files into flat dot-notation keys for compatibility with certain localization libraries or platforms.
How to Use
- Paste your nested JSON object into the input field — this can be any valid JSON including deeply nested objects, mixed arrays, and varied value types.
- Click the Flatten button (or the tool will process automatically) to recursively traverse the entire object tree and generate the flattened output.
- Review the result, where each key is now a dot-notation path representing the full hierarchy from root to leaf, such as 'config.database.host'.
- For arrays in your input, note that each element is represented by its numeric index in the key path, for example 'users.0.name' and 'users.1.name'.
- Copy the flattened JSON output using the Copy button and paste it directly into your database query, config system, or downstream application.
- If the output is larger than expected, use it as a diagnostic tool — the flattened keys give you a complete inventory of every value stored in your original structure.
Features
- Recursive dot-notation flattening that handles unlimited nesting depth without losing any values or structural information.
- Array support with zero-based numeric index notation, so every array element is individually accessible as its own flat key.
- Preserves all JSON value types including strings, numbers, booleans, nulls, and even empty strings without coercion or transformation.
- Produces strictly valid JSON output that can be immediately parsed, stored, or transmitted without any additional processing.
- Instant in-browser processing with no server upload required, keeping your sensitive configuration and data completely private.
- Clean, readable key format that makes the full path to any nested value immediately understandable at a glance.
- Handles mixed structures containing both objects and arrays at any level of nesting within the same input document.
Examples
Below is a representative input and output so you can see the transformation clearly.
{
"user": {"name": "Ada", "role": "admin"}
}{
"user.name": "Ada",
"user.role": "admin"
}Edge Cases
- Very large inputs may take a few seconds to process in the browser. If performance slows, split the input into smaller batches.
- Mixed formatting (tabs, line breaks, or inconsistent delimiters) can affect output. Normalize spacing first if needed.
- Flatten JSON Object follows the selected options strictly. If the output looks unexpected, re-check option settings and input format.
Troubleshooting
- Output looks unchanged: confirm the input contains the pattern this tool modifies and that the correct options are selected.
- Output differs from a previous run: confirm that the input and every option match, because deterministic tools should repeat when the settings are identical.
- Unexpected characters: check for hidden whitespace or encoding issues in the input and try normalizing first.
- Slow processing: reduce input size or try a modern browser with more available memory.
Tips
When working with very large or deeply nested JSON, scan the flattened keys first to understand the full shape of your data — it acts as an instant schema map. If you plan to store flattened keys in a database column, be aware that deeply nested paths can generate long key strings; consider whether your schema has column name length limits. For round-tripping data, pair this tool with an unflatten utility so you can restore the original nested structure after processing. When flattening JSON that contains dot characters in its original keys (e.g., domain names or version strings), be cautious — the dot separator can cause ambiguity when unflattening later.
Frequently Asked Questions
What is JSON flattening and what does it produce?
JSON flattening is the process of taking a multi-level nested JSON object and converting it into a single-level object where each key represents the full path to a value using dot notation. For example, `{"a":{"b":1}}` becomes `{"a.b":1}`. The output is a standard, valid JSON object — it just has no nested objects or arrays inside it. All the original values are preserved; only the structure changes.
How are arrays handled when flattening JSON?
Arrays are flattened using zero-based numeric index notation. Each element in an array gets its own key with the element's index as part of the path. For example, `{"colors":["red","blue"]}` becomes `{"colors.0":"red","colors.1":"blue"}`. If array elements are themselves objects, their properties are also flattened: `{"users":[{"name":"Alice"}]}` becomes `{"users.0.name":"Alice"}`. The ordering of array elements is preserved through the index numbering.
Can I reverse a flattened JSON object back to its original nested structure?
Yes, this is called "unflattening" and it's the inverse operation. By parsing the dot-notation keys and reconstructing the nested hierarchy, you can restore the original structure. Many libraries (such as the `flat` npm package) support both flatten and unflatten operations. However, if your original JSON keys contained literal dots (e.g., a domain name or version string like `"1.0.0"`), unflattening can produce incorrect results since the dot is ambiguous as both a separator and a literal character.
Why would I need to flatten JSON for a database?
Relational databases organize data in flat tables with fixed columns, so they cannot natively store a nested JSON object as-is without using a JSON column type. When you want to map each nested property to its own database column — for easier querying, indexing, and filtering — you need to flatten the object first. The flattened key names can map directly to column names, and the values map to the row's cell values. This is especially common when loading API response data into PostgreSQL, MySQL, or data warehouses like BigQuery.
Does flattening work on JSON with mixed arrays and objects?
Yes, the flattening algorithm handles any combination of nested objects and arrays at any depth. A JSON structure that alternates between objects and arrays across multiple levels will be fully traversed, and every leaf value will appear in the flattened output with a complete dot-and-index-notation key. The tool handles real-world JSON from APIs, which rarely has a perfectly uniform structure, without any configuration needed.
What's the difference between flattening JSON and using JSON Pointer or JSONPath?
JSON Pointer (RFC 6901) and JSONPath are query syntaxes for accessing values within a nested JSON structure — they let you reference a specific value by path without changing the document. JSON flattening is a transformation: it restructures the entire document into a new flat format. Flattening is best when you need to change the shape of the data for storage or processing; JSON Pointer and JSONPath are best when you need to extract or reference specific values from an existing nested document.