首页 Home/JSON 格式化 / JSON Formatter

JSON 格式化 · JSON Formatter

JSON 格式化是在线开发者最常用的工具之一。本工具可以 beautify(美化)杂乱的 JSON 字符串,把它转换成带有清晰缩进的层级结构;也可以压缩(minify)掉所有空白字符,用于接口传输或存储。

JSON formatting is one of the most used online developer utilities. This tool beautifies messy JSON into a clearly indented hierarchy, or minifies it by stripping whitespace for transport and storage.

JSON 格式化JSON Formatter
INPUT0 chars
OUTPUT
结果会显示在这里
提示:所有处理都在你的浏览器本地完成。输入后自动更新结果

JSON 格式化 / JSON Formatter

功能介绍(中文)

JSON 格式化是在线开发者最常用的工具之一。本工具可以 beautify(美化)杂乱的 JSON 字符串,把它转换成带有清晰缩进的层级结构;也可以压缩(minify)掉所有空白字符,用于接口传输或存储。

除了基础的格式化,工具还提供可折叠的树形预览,方便查看深层嵌套结构;支持递归按 key 排序,让两份 JSON 的差异一目了然。解析失败时会精确标出错误所在的行、列和字符位置,并画出插入符。

“一键修复”采用容错词法解析,能处理注释、单引号、未加引号的 key、全角标点、尾随或缺失逗号、缺失冒号、裸字符串值、括号不配对、未转义换行、undefined / NaN 等常见小错误,修复后自动重新格式化。

Overview (English)

JSON formatting is one of the most used online developer utilities. This tool beautifies messy JSON into a clearly indented hierarchy, or minifies it by stripping whitespace for transport and storage.

Beyond basic formatting, it offers a collapsible tree view for deeply nested data, recursive key sorting for easy comparison, and precise error reporting with line, column, character position and a caret marker when parsing fails.

The one-click repair uses a tolerant tokenizer to fix common mistakes: comments, single quotes, unquoted keys, full-width punctuation, trailing or missing commas, missing colons, bare string values, unbalanced brackets, unescaped newlines, undefined and NaN.

功能特点(中文)

  • 美化与压缩一键切换,缩进统一为 2 空格
  • 可折叠树形视图,折叠状态在重新渲染后保留
  • 递归按 key 排序,数组顺序保持不变
  • 错误定位到行、列与字符位置,并显示插入符
  • 容错修复 21 类常见 JSON 语法问题

Features (English)

  • One-click beautify and minify with clean 2-space indentation
  • Collapsible tree view that preserves fold state on re-render
  • Recursive key sorting while keeping array order intact
  • Error location with line, column, character position and caret
  • Tolerant repair for 21 common JSON syntax problems

常见问题 / FAQ

JSON 格式化会上传我的数据吗?

不会。所有解析、排序、修复和渲染都在你的浏览器本地完成,页面不向服务器发送任何输入内容或转换结果。

Does JSON formatting upload my data?

No. Parsing, sorting, repair and rendering all happen locally in your browser. No input or result is ever sent to the server.

“一键修复”能处理哪些错误?

可以处理注释、单引号字符串、未加引号的 key、中文全角标点与括号、尾随逗号、对象或数组缺失逗号、缺失冒号、裸字符串值、缺失或多出的括号、未转义换行、undefined / NaN / True 等非法字面量、数字前导零、BOM 和结尾分号等 21 类问题。

What errors can one-click repair fix?

It fixes 21 categories: comments, single-quoted strings, unquoted keys, full-width punctuation, trailing or missing commas, missing colons, bare string values, unbalanced brackets, unescaped newlines, invalid literals such as undefined / NaN / True, leading zeros, BOM and trailing semicolons.

JSON 和 JSONP 有什么区别?

JSON 是一种数据交换格式;JSONP 是利用 script 标签跨域加载数据的技术,本质是把 JSON 包装成函数调用。JSONP 存在安全风险,现代开发更推荐使用 CORS。

What is the difference between JSON and JSONP?

JSON is a data interchange format, while JSONP is a cross-origin loading technique that wraps JSON in a function call via a script tag. JSONP carries security risks; CORS is recommended today.

为什么要按 key 排序 JSON?

JSON 对象理论上无序,但不同系统序列化时字段顺序可能不同。排序后两份数据更容易人工比对,也便于做差异检测和生成稳定的签名。

Why sort JSON keys?

JSON objects are logically unordered, but different systems serialize fields differently. Sorting makes two documents easier to compare, enables diffing and produces stable representations for signing.

← 返回全部工具 / All tools

已复制到剪贴板