JSON 扁平化器和反扁平化器(点表示法)
指导
JSON Flattener & Unflattener
Convert nested JSON structures to flat dot-notation key-value pairs, or reverse the process to rebuild nested objects from flat keys. This bidirectional tool handles deeply nested objects, arrays with index notation, custom delimiters, and configurable depth limits — all client-side in your browser. Perfect for working with NoSQL databases, environment variable configs, or any system that requires flat key-value formats.
如何使用
Paste your JSON into the input area and select the operation mode — Flatten to convert nested JSON into dot-notation, or Unflatten to rebuild nested structures from flat keys. Choose your preferred delimiter (dot, slash, underscore, or custom), select how arrays should be notated, and set an optional depth limit. The output updates automatically with syntax highlighting, ready to copy or download.
特征
- 双向转换 – Flatten nested JSON to dot-notation or unflatten flat keys back to nested structures
- Custom Delimiters – Use dot (
.), slash (/), underscore (_), or any custom separator for key paths - Array Notation Options – Choose between dot-index (
arr.0.name) or bracket notation (arr[0].name) - Depth Limiting – Flatten only N levels deep, keeping deeper structures as nested values
- Auto-Detect Mode – Automatically suggests flatten or unflatten based on your input structure
- Type Preservation – Correctly preserves numbers, booleans, null values, and strings through round-trips
- 美化输出 – Configurable indentation (2 or 4 spaces, or compact) with syntax highlighting
常问问题
-
What is JSON flattening and when is it useful?
JSON flattening converts a nested object structure into a single-level object where each key represents the full path to a value using dot notation. For example, a nested user.name.first path becomes a single flat key. This is useful when working with NoSQL databases like Redis or DynamoDB that store flat key-value pairs, when mapping nested configs to environment variables, or when you need to compare two deeply nested objects field by field.
-
How are arrays handled during flattening?
Arrays are flattened using numeric indices in the key path. With dot-index notation, array elements get keys like items.0 and items.1. With bracket notation, they become items[0] and items[1]. When unflattening, the tool detects numeric path segments and correctly reconstructs arrays rather than creating objects with numeric string keys.
-
What does the depth limit do?
The depth limit controls how many levels deep the flattener will recurse. With a depth limit of 2, deeply nested objects are only partially flattened, preserving nested structures beyond that level. Setting depth to 0 means unlimited flattening. This is useful when you want to partially flatten a structure while preserving some nested grouping.
-
Can flattening and unflattening round-trip without data loss?
Yes, as long as you use the same delimiter and array notation settings for both operations. Flattening followed by unflattening with matching settings will reproduce the original nested structure with all data types preserved — strings, numbers, booleans, null values, arrays, and nested objects all survive the round trip. The only caveat is that empty objects and empty arrays may be lost since they contain no leaf values to flatten.
