跳到主要内容
Toolioz logoToolioz
数据格式化

JSON 格式化与校验

在浏览器中格式化、校验或压缩 JSON,也可以转换为 YAML 或 TypeScript。

格式化
转换

结果

(格式化后将在此显示输出)
摘要与答案
开发工具

Format, validate, and convert JSON to TypeScript or YAML

This page pretty-prints JSON with 2 or 4 spaces, minifies it, and can emit YAML or TypeScript from a value that parses. The text is not uploaded. The site still loads scripts and analytics.

要点

  • Pasted JSON stays in the tab when the page is labelled local processing. Analytics for the website still load.
  • TypeScript interfaces come from json-to-ts and the parsed sample.
  • The YAML converter turns parsed JSON into YAML syntax.
  • A parse error shows the JSON.parse message. The page does not highlight a line.

常见问题

标明本地处理的页面会在此标签页中完成格式化和转换。JSON 不会上传至 Toolioz。网站仍会加载脚本和分析服务。

YAML 通过 js-yaml 生成,缩进为 2 个空格。TypeScript 使用 json-to-ts 处理解析后的值。两种转换均在 JSON.parse 成功后执行,文本不会上传。

JSON.parse 会拒绝尾随逗号、单引号和未加引号的键。页面显示解析器的提示,且不会高亮代码行。文本不会上传。

编辑说明 · 审阅日期 10 September 2026

What this JSON formatter does with invalid input

The formatter pretty-prints JSON that already parses, and it reports the first syntax error when the text is not JSON. It is not a schema validator and it does not send the document to Toolioz when the page is labelled local processing.

Parse errors you will actually see

JSON requires double-quoted keys, no trailing commas, and no comments. A trailing comma after the last property is valid in JavaScript objects and invalid in JSON. Single quotes around strings fail. `undefined` is not a JSON value. The engine stops at the first violation and shows a position; fix that before looking for a second error.

Huge minified files can freeze a tab because parsing is synchronous on the main thread. Split the file or use a desktop tool if the browser complains. Formatting does not prove the payload matches an API contract. That check is JSON Schema, on a different page.

Privacy note

Tokens, passwords, and PII pasted here stay in the tab only if the page states local processing. The website still loads scripts and analytics. Do not paste production secrets into any website, including this one, if your policy forbids it.

计算示例

  • Trailing comma

    {"ok": true,} fails. {"ok": true} parses. Remove the comma after true.

本页的适用范围与限制

  • Does not repair YAML, TOML, or JavaScript object literals automatically.
  • Duplicate keys: JSON.parse keeps the last value; that may not be what the API author intended.

资料来源