JSON 格式化器

格式化 JSON 文本、验证结构并压缩输出。

// about

工具介绍

JSON 文本挤在一起时很难阅读。这个工具能自动加上换行和缩进,让数据结构一目了然。

如何使用

  1. 把需要整理的 JSON 文本粘贴到上方输入框。
  2. 点击“运行”进行美化,或者勾选“压缩”制作紧凑版本。
  3. 复制转换后的干净文本即可使用。

人们为何使用此工具

  • 一键将混乱的 JSON 排版得整整齐齐。
  • 快速发现少写逗号或引号等语法错误。
  • 支持一键压缩(Minify),方便快速传输。

常见问题解答 (FAQ)

什么是 JSON?

JSON 是计算机之间传输数据时常用的一种简单格式,使用大括号和引号组织信息。

我的数据会被上传到服务器吗?

不会,所有计算都在您的浏览器本地完成,绝对安全保密。

提示错误怎么办?

通常是因为漏掉了双引号或逗号,请仔细检查一下文本细节。

指南 · 数据 · 约 3 分钟

修复 JSON 语法错误:7 个最常见的错误与 JSON 整理方法

API 响应、配置文件、日志——JSON 是开发者读得最多的数据格式。然而一个逗号或引号就可能引发 “Unexpected token” 错误。下面介绍如何快速找到原因。

JSON(JavaScript Object Notation)是由 RFC 8259 和 ECMA-404 标准化的文本格式。它源自 JavaScript,如今几乎所有语言都支持。值的类型只有六种:字符串、数字、布尔值(true/false)、null、数组和对象。

{
  "id": 1024,
  "name": "AIBIZAP",
  "active": true,
  "tags": ["tools", "guides"],
  "owner": null
}
JSON 基础知识、导致解析错误的七个错误、大数字和日期的陷阱,以及如何把 JSON 转换成类或数据库表。
阅读指南 →
用 AI 自己做

用 AI 亲手打造这个工具

想要自己的版本?把下面的任务提示词粘贴到 AI 聊天中,或将技能文件保存到 AI 编程助手。其中包含我们开发此工具时整理的功能、边界情况和测试用例。

提示词和技能以英文提供,AI 工具在任何语言环境下都能很好地理解。

AI 任务提示词

直接粘贴到 Claude、ChatGPT、Gemini 等 AI 聊天中即可。

You are an experienced full-stack web developer. Build a web tool called "JSON 格式化器" that meets the requirements below.

## Goal

Build a tool that validates JSON and pretty-prints or minifies it.

## Core features

- Validation with error line and column
- Indent with 2 spaces, 4 spaces or tabs
- Minify mode
- Optional alphabetical key sorting
- Copy result and download as .json

## Inputs

- JSON text
- Indentation, sorting and mode options

## Outputs

- Formatted or minified JSON
- Error message with position

## Edge cases and handling rules

- Explain common errors such as trailing commas, single quotes and comments in plain language
- Preserve integers larger than 2^53 exactly
- Strip a leading BOM
- Stay responsive with multi-megabyte input

## Implementation requirements

- Build it as a single page (HTML, CSS, JavaScript) that runs entirely in the browser, and never send the user's input to a server.
- Make the UI responsive and easy to use on mobile; label every input and keep everything keyboard accessible.
- Add a Copy button for results and show clear, friendly error messages for invalid input.
- Keep the core logic in functions separate from the UI so it can be unit-tested.

## Definition of done (test cases)

- '{"a":1,}' is reported as a trailing comma error
- Formatting then minifying keeps the same meaning
- 12345678901234567890 is preserved

First outline your implementation plan in at most five lines, then write the complete code, and finally explain how to check the test cases above.

技能 (SKILL.md)

在 Claude Code 等 AI 编程助手中保存为 .claude/skills/build-json-formatter/SKILL.md,以后开发或修改此工具时可重复使用。

---
name: build-json-formatter
description: Use when building or changing a JSON 格式化器 tool. Build a tool that validates JSON and pretty-prints or minifies it.
---

# Build: JSON 格式化器

## Goal

Build a tool that validates JSON and pretty-prints or minifies it.

## Workflow

1. Review the required features, inputs and outputs below and ask about anything missing first.
2. Implement the core logic as pure functions separate from the UI.
3. Check the logic against the test cases in the verification list.
4. Build a responsive UI with an input form, a result area and a Copy button.
5. Reproduce each edge case listed under Rules and refine the error messages.

## Core features

- Validation with error line and column
- Indent with 2 spaces, 4 spaces or tabs
- Minify mode
- Optional alphabetical key sorting
- Copy result and download as .json

## Inputs

- JSON text
- Indentation, sorting and mode options

## Outputs

- Formatted or minified JSON
- Error message with position

## Rules

- Explain common errors such as trailing commas, single quotes and comments in plain language
- Preserve integers larger than 2^53 exactly
- Strip a leading BOM
- Stay responsive with multi-megabyte input
- Build it as a single page (HTML, CSS, JavaScript) that runs entirely in the browser, and never send the user's input to a server.

## Verification

- [ ] '{"a":1,}' is reported as a trailing comma error
- [ ] Formatting then minifying keeps the same meaning
- [ ] 12345678901234567890 is preserved

交给 AI 时的小技巧

  • 在第一行写明技术栈(如 React、Vue 或纯 HTML),生成的代码会更贴合你的项目。
  • 在接受代码前,请让 AI 运行列出的测试用例并展示结果。
  • 不要把真实密码、客户数据或 API 密钥粘贴到提示词中,请用示例值代替。