JSON ⇄ YAML Converter|JSON / YAML 格式转换

JSON ⇄ YAML 转换器 | JSON ⇄ YAML Converter

JSON ⇄ YAML 转换器 JSON ⇄ YAML Converter

在 JSON 与 YAML 文本之间进行双向格式转换,支持 JSON → YAML 与 YAML → JSON。
Convert between JSON and YAML in both directions: JSON → YAML and YAML → JSON.

1. 输入与转换方向 · Input & Direction
根据需要选择转换方向。
Choose the direction you want to convert.
JSON → YAML: 适合将 API 返回、配置文件或日志中的 JSON 转为更易读的 YAML。
JSON → YAML: Good for transforming API responses, configs or logs into human-friendly YAML.
YAML → JSON: 适合将 YAML 配置转为 JSON,用于前端、本地存储或接口调用。
YAML → JSON: Helpful when converting YAML configs to JSON for frontend, storage or API calls.
建议保持缩进整齐(2 或 4 个空格),避免使用 Tab 混合缩进。
For best results, use consistent indentation (2 or 4 spaces) and avoid mixing tabs and spaces.

对于 JSON:需要有效的 JSON 语法(双引号、逗号位置正确等)。
For JSON: input must be valid JSON (double quotes, commas, etc. in correct places).
结果区为只读,避免误操作改动原始转换结果。若需编辑,请复制到其他编辑器中。
Output is read-only to prevent accidental edits. Copy it into your own editor if you need to modify it.

支持多行、带注释的 YAML。对于高级 YAML 特性(锚点、别名等),转换结果可能简化为普通结构。
Supports multi-line and commented YAML. For advanced YAML features (anchors, aliases, etc.), output may be simplified.
缩进 · Indent
YAML → JSON 时生效 Affects YAML → JSON only
选择 JSON 输出的可读性:
• 2/4 空格:更易读,适合调试与人工查看;
• 压缩:去除多余空格与换行,适合网络传输或存储。

Choose readable (pretty-printed) or compact JSON output depending on your use case.
2. 使用小贴士 · Tips for Use
  • 1)JSON → YAML:
    适合将后端接口返回的 JSON、前端配置文件或日志数据,转换为结构更清晰的 YAML,便于阅读与修改。
    Use this when you want to turn API responses, frontend configs or logs into more readable YAML structures.
  • 2)YAML → JSON:
    当你在 Kubernetes、CI/CD 或其他配置文件系统中使用 YAML,而目标程序只接受 JSON 时,可以快速进行格式转换。
    When working with YAML in Kubernetes, CI/CD or other config systems but a target program expects JSON, convert here.
  • 3)错误排查:
    若转换失败,本工具会在下方展示错误信息与大致位置(例如第几行)。可根据提示返回编辑器修正。
    If conversion fails, the tool shows an error and approximate location (line number). Fix issues in your editor and retry.
  • 4)语法差异提醒:
    JSON 要求所有键名使用双引号,并严格区分布尔值 true/false"true"/"false" 字符串; YAML 更宽松,允许缩进表示层级、使用注释等。转换时,请留意这些语法差异带来的变化。
    JSON requires quoted keys, strict booleans (true/false) and a very rigid structure; YAML is more flexible with indentation, comments, etc. Watch out for these differences when converting.

说明:本工具使用浏览器端 JavaScript 与开源 YAML 解析库进行转换,不上传数据到服务器。 适用于一般 JSON/YAML 文本转换场景,但不保证涵盖所有极端或非标准写法。
Note: Conversion is done entirely in your browser using JavaScript and an open-source YAML parser. It is suitable for common JSON/YAML use cases but may not handle every exotic or non-standard edge case.