TOOL / 01
JSON / YAML / XML 转换
粘贴 JSON、YAML 或 XML,直接转换为其他格式。数据只在当前浏览器中处理。
格式化
自动缩进,让复杂的数据结构更易读。
校验
有语法问题时,会提示具体的位置。
隐私
零上传、零存储,内容始终留在本地。
一、什么时候需要这个工具
三种格式各有各的地盘,实际工作里经常要在它们之间来回搬数据:接口返回的是一行挤在一起的 JSON,肉眼几乎没法读;Kubernetes、CI 流水线、各类配置文件用 YAML;而一些老系统的配置文件和移动端布局文件坚持用 XML。
- 调试接口:把
curl拿到的压缩 JSON 粘进来,一键缩进成能看懂的结构; - 改配置:把 YAML 转成 JSON 放进程序里读,或者反过来把 JSON 改写成 YAML;
- 排查报错:先校验格式,让工具指出出错的位置,再去改内容。
二、怎么用
- 把内容粘贴进输入框(也可以点「示例」先看看效果);
- 选一个转换方向:转 JSON、压缩 JSON、转 YAML、转 XML;
- 看下方状态提示:成功会说明结果,失败会指出错误在第几行;
- 点「复制」取走结果。
三、几个一定会踩到的坑
JSON 比你想的更严格。它不允许尾随逗号([1,2,])、不允许注释、字符串必须用双引号。这三条是「从 JavaScript 对象复制过来」时最常见的失败原因。
YAML 的类型推断很主动。version: 1.20 会被当成数字 1.2,on、yes 在部分解析器里会被读成布尔值。要保留原样,请加引号:version: "1.20"。
YAML 的锚点和别名会被展开。用 &anchor 和 *anchor 复用的段落,转成 JSON 后会变成完整复制的内容,体积可能变大,但语义不变。
XML 是有序的,JSON 对象是无序的。XML 同名标签会转成数组,属性会带上 @ 前缀;往返转换后文本排版可能变化,这是格式差异导致的,不是数据丢失。
四、数据安全
所有解析和转换都在你的浏览器里完成,不会把内容发到任何服务器。不过仍建议:涉及密钥、令牌、身份证号的内容,用完随手点「清空」,不要把生产凭据留在公共电脑的输入框里。
When you need this
Each format owns a different corner of the world, and real work keeps moving data between them: APIs return JSON squeezed onto one line, Kubernetes and CI pipelines speak YAML, and older systems still insist on XML.
- Debugging an API — paste the minified JSON from
curland get a structure you can actually read; - Editing config — convert YAML to JSON to load it in code, or rewrite JSON as YAML;
- Chasing a parse error — validate first, let the tool point at the line, then fix the content.
How to use it
- Paste your content (or press Sample to see the tool in action);
- Pick a direction: to JSON, minify JSON, to YAML, to XML;
- Read the status line — success describes the output, failure names the line;
- Press Copy to take the result away.
Pitfalls you will hit
JSON is stricter than you remember. No trailing commas ([1,2,]), no comments, double quotes only. Those three break most attempts at pasting straight from JavaScript.
YAML infers types eagerly. version: 1.20 becomes the number 1.2, and on or yes become booleans in some parsers. Quote the value to keep it literal: version: "1.20".
YAML anchors are expanded. Blocks reused via &anchor and *anchor come out as full copies in JSON: same meaning, larger payload.
XML is ordered, JSON objects are not. Repeated tags become arrays and attributes gain an @ prefix. Round-tripping may reflow the text, but no data is lost.
Data safety
Parsing and conversion happen entirely in your browser; nothing is uploaded. Still, if the content carries keys, tokens or ID numbers, clear the box when you are done — especially on a shared machine.