YAML ↔ JSON Converter|YAML/JSON 互转

YAML ↔ JSON Converter | YAML/JSON 互转

YAML ↔ JSON Converter YAML/JSON 互转

配置文件常用转换:YAML 与 JSON 相互转换,支持格式化(Pretty)、压缩(Minify)、校验与一键复制。
Convert YAML to JSON and JSON to YAML with validation, pretty print, minify, and copy-to-clipboard.

1. 输入内容 · Input
建议:如果你准备把结果粘贴到配置仓库或发给同事,优先用 Pretty(带缩进)更易读。
Tip: Use Pretty output for readability; use Minify only when you truly need compact output.
支持粘贴多行文本。YAML 常见缩进为 2 空格;JSON 必须是合法的对象或数组文本。
Paste multiline content. YAML commonly uses 2-space indentation; JSON must be valid object/array text.
输出默认只读,避免误操作;你可以点击 “复制 / Copy” 直接复制。
Output is read-only by default to prevent accidental edits; use Copy to grab it instantly.
状态:就绪 / Status: Ready (本工具纯前端运行,不上传你的内容)(Runs locally in your browser; no uploads.)
2. 输出规则 · Output Rules
  • YAML → JSON:工具会把 YAML 解析成对象/数组,再用你选择的缩进输出 JSON。
    YAML → JSON: The tool parses YAML into an object/array and prints JSON with your chosen indentation.
  • JSON → YAML:工具会先解析 JSON,再输出 YAML(更适合做配置文件、K8s、CI/CD 等场景)。
    JSON → YAML: The tool parses JSON first and then emits YAML, commonly used for configs (K8s, CI/CD).
  • 注意:YAML 支持注释(# …),JSON 不支持注释;所以 YAML → JSON 后注释会消失。
    Note: YAML supports comments (# ...) but JSON does not, so comments will be lost in YAML → JSON.
  • 数字与字符串:YAML 可能把 001 识别为数字或字符串,取决于写法;建议需要保留前导零时加引号。
    Numbers vs strings: YAML typing can be tricky; quote values if you must preserve leading zeros.

说明:本工具用于格式转换与调试辅助,不对你的配置正确性负责(例如字段语义、业务规则等)。建议转换后配合你的实际程序/平台做一次校验。
Note: This tool focuses on syntax/format conversion only. It does not validate business rules. Always validate the converted config in your target system.

3. 使用说明 · Notes

✅ 典型使用场景(中文)
1)你从网上抄到一段 YAML(比如 Docker Compose / Kubernetes / GitHub Actions),但你的程序只接受 JSON:选择 YAML → JSON,点 “转换”。
2)你手里是 JSON(比如接口返回的对象),但你希望生成更适合写配置的 YAML:选择 JSON → YAML,点 “转换”。
3)你想把输出变得更易读:点 “美化输出”。想要更短(例如发 IM、写日志):点 “压缩输出”。
4)你需要快速发给同事或粘贴到工单:点 “复制输出”。(浏览器会把内容放入剪贴板)

✅ Common scenarios (English)
1) You have a YAML snippet (Docker Compose / Kubernetes / CI configs) but your tool only accepts JSON: choose YAML → JSON and click Convert.
2) You have JSON (API response / data object) but want a config-friendly format: choose JSON → YAML and Convert.
3) Need readability? Use Pretty. Need compact output for chat/logs? Use Minify.
4) Sharing quickly? Click Copy Output to put the result on your clipboard.

🧠 小技巧(中文)
• YAML 特别怕缩进错误:建议统一用 2 空格缩进,不要混用 Tab。
• 如果你在 YAML 里写了日期、开关值:on/offyes/no2025-12-17 这类可能会被当成特殊类型;不确定就用引号包起来。
• 如果你想“交换输入和输出”继续做二次转换或对照:点 “交换输入/输出”。

🧠 Tips (English)
• YAML is indentation-sensitive: prefer 2 spaces and avoid tabs.
• YAML may auto-cast values (dates/booleans). If you want a strict string, wrap it in quotes.
• Use “Swap” to quickly run a second pass or compare transformations.

隐私说明:所有转换都在浏览器本地完成,本页面不会把你的 YAML/JSON 上传到服务器。
Privacy: Everything runs locally in your browser. This page does not upload your YAML/JSON to any server.