JSON Formatter & Validator
One input per line. Output is numbered to match the input order.
Pinned tools are listed in your favourites on the home page.Copies a link to this tool that carries your current input, so it opens ready to run.Gives you an iframe snippet for putting this tool on your own site.
Ctrl+Enter Run · Ctrl+Shift+C Copy · Esc Clear
Understand JSON Formatter & Validator
这个格式化工具用统一的缩进重新打印 JSON,也能把它折回单行,或者告诉你它在哪里出了问题。
How it works
文本会被解析成真正的值,然后再打印出来,因此输出是规范化的,而不只是重新排布空格:空白被重新生成,转义序列被归一化,1e3 会变回 1000。任何不合法的 JSON 都会在解析这一步失败,错误信息会指出解析器放弃时所在的字符位置。压缩就是把缩进设为空的同一次往返。
When to use it
- 在读一条单行 API 响应之前,先让它变得可读。
- 定位某个服务拒绝的载荷中语法错误的字符偏移量。
- 在把配置或夹具嵌入字符串字面量之前先压缩它。
- 把两份载荷归一化为相同缩进,让 diff 显示真实差异而不是格式噪声。
Watch out for
- JSON 不是 JSONC,也不是 JSON5。注释和尾随逗号都是语法错误,这就是 tsconfig.json 和 .eslintrc 常常在这里失败的原因——它们是带注释的 JSON,属于另一种格式。
- 超过 2^53 − 1 的整数在往返中会丢失精度。像 9007199254740993 这样的雪花 ID 回来会变成 ...992,于是格式化后的输出悄悄成了另一个数字。大 ID 请用字符串保存。
- 重复的键会静默合并。{"a":1,"a":2} 解析时毫无怨言,最后一个值胜出,因此真正有歧义的输入会被格式化得像没问题一样。
- 校验只检查语法。一条响应可以是完美的 JSON,同时缺少你代码需要的每一个字段。
Not the right tool for: 检查数据是否符合预期结构——那是 JSON Schema 校验器要做的事。
Frequently Asked Questions
JSON 是什么?
JSON(JavaScript Object Notation)是一种轻量级数据交换格式,人类易于读写,机器也易于解析和生成。
常见的 JSON 错误有哪些?
常见错误包括尾随逗号(JSON 不允许)、用单引号代替双引号、键没加引号,以及 undefined/NaN 这类值。
格式化和压缩有什么区别?
格式化会加上缩进和换行以便阅读。压缩会去掉所有不必要的空白以减小体积——适合生产环境的 API。
How to Use JSON Formatter & Validator
- Paste or type your input in the input area above.
- The tool processes your input automatically or click Run.
- Copy or download the result using the action buttons.
- Use Ctrl+Enter to run quickly from the keyboard.