JSON数据扁平化

把嵌套结构摊平成 a.b.c 形式的单层键值。

扁平化flatten
关于「JSON数据扁平化」

它属于「JSON 工具」分类:JSON 的格式化、结构变换与各种数据格式互转。

  • 把多层嵌套的对象摊平成<b>单层键值对</b>,键名用路径表示,例如 <code>user.address.city</code>。
  • 数组默认展开为 <code>tags[0]</code> 形式;取消勾选后会变成 <code>tags.0</code>。
  • 分隔符可自定义,当键名本身含有点号时,改用 <code>/</code> 或 <code>__</code> 可避免歧义。
  • 空对象与空数组会作为叶子节点保留,反扁平化时可以完整还原。
  • 常用于国际化词条、配置项对照表,以及把嵌套数据导入到扁平的表格里。

完全免费、无需注册;所有处理都在浏览器本地完成,文件不会上传到任何服务器。

相关关键词:JSON数据扁平化、JSON 工具、扁平化、flatten、在线工具、免费

如何使用「JSON数据扁平化」
  1. 打开工具:打开「JSON数据扁平化」页面,无需注册、无需安装任何软件。
  2. 准备输入:准备好要处理的内容或文件:文本可直接粘贴,文件可拖入页面(本工具属于「JSON 工具」)。
  3. 填入内容:把内容粘贴进输入框,或把文件拖入页面;也可以点击「示例」先填入样例数据试一下。
  4. 设置选项并处理:按需调整页面上的选项,然后点击处理 / 转换 / 生成按钮。
  5. 获取结果:处理完全在浏览器本地完成,结果可直接复制或下载,文件不会上传到任何服务器。
常见问题
扁平化有什么用?
很多场景只接受单层结构,比如 i18n 语言包、环境变量、表格的列。把嵌套 JSON 摊平后,就能直接对照和检索每一个字段的完整路径。
可以还原回去吗?
可以,使用配套的「JSON数据反扁平化」工具,用相同的分隔符设置即可还原成原来的嵌套结构。
键名里本来就有点号怎么办?
这种情况下用默认的点号分隔会产生歧义,建议把分隔符改成 <code>/</code>、<code>|</code> 或 <code>__</code> 等不会出现在键名中的字符。
Flatten JSON (English)

Flatten nested structures into a.b.c single-level keys.

Belongs to “JSON Tools”: Format, transform and convert JSON to and from various data formats.

  • Collapses deeply nested objects into <b>flat key-value pairs</b> with path-based keys like <code>user.address.city</code>.
  • Arrays expand as <code>tags[0]</code> by default; uncheck to use <code>tags.0</code> instead.
  • The separator is customizable; if a key already contains a dot, switch to <code>/</code> or <code>__</code> to avoid ambiguity.
  • Empty objects and arrays are kept as leaf nodes, so you can fully restore them via unflatten.
  • Handy for i18n bundles, config tables, and importing nested data into flat spreadsheets.

Free, no sign-up; everything runs locally in your browser and files are never uploaded.

Keywords: Flatten JSON, JSON Tools, flatten, online tool, free

How to use it

  1. Open the tool:Open the “Flatten JSON” page — no sign-up and nothing to install.
  2. Prepare the input:Prepare the content or file to process: paste text or drop a file onto the page (this tool belongs to “JSON Tools”).
  3. Provide the input:Paste your content into the input box or drop a file onto the page; you can also click “Sample” to try example data first.
  4. Adjust options and run:Adjust the options if needed, then click the process / convert / generate button.
  5. Get the result:Everything runs locally in your browser; copy or download the result — your files are never uploaded.

FAQ

What is flattening for?
Many systems accept only flat structures — i18n bundles, env vars, spreadsheet columns. Flattening lets you compare and look up every field by its full path.
Can it be reversed?
Yes — use the companion “JSON unflatten” tool with the same separator to restore the original nested structure.
What if a key already has a dot?
A default dot separator is then ambiguous; change it to a character not present in keys, such as <code>/</code>, <code>|</code> or <code>__</code>.

More tools in JSON Tools

  • JSON Formatter/Minifier — Beautify, minify, validate and highlight JSON.
  • Sort JSON Keys — Recursively sort object keys alphabetically to ease diffing.
  • Unflatten JSON — Restore dotted-path objects into nested structures.
  • JSON to CSV — Convert an array of objects into a downloadable CSV.
  • CSV to JSON — Parse CSV text or files into a JSON array.
  • JSON to Excel — Export an array of objects as an .xlsx workbook.
  • Excel to JSON — Upload an Excel file and convert sheets to JSON.
  • JSON to XML — Convert JSON structures into well-indented XML.
  • XML to JSON — Parse an XML document into an equivalent JSON object.
  • JSON to YAML — Convert JSON into more readable YAML.
  • YAML to JSON — Parse YAML config into standard JSON.
  • JSON to SQL — Generate INSERT statements and CREATE TABLE DDL from arrays.
  • SQL to JSON — Reverse-engineer JSON data from INSERT statements.
  • JSON to Base64 — Convert JSON to and from Base64 with UTF-8 support.
  • JSON ⇄ Cookie — Convert between Cookie strings and JSON key-values.
  • JSON Diff — Recursively compare two JSON documents, marking add/delete/change.

返回崽崽工具箱首页