工具 指南
developer 免费 无需注册

YAML验证器和格式化工具

验证YAML语法并将其转换为格式化的JSON——完全在浏览器中运行。

正在加载工具…

关于此工具

粘贴YAML并即时检查其是否有效。内置解析器支持标量(字符串、数字、布尔值、null)、通过缩进的嵌套对象以及带-前缀的序列。切换到JSON视图查看YAML转换后的格式化JSON。错误消息显示行号以便快速调试。

使用方法

  1. 1 将YAML粘贴到输入文本框中。
  2. 2 点击"验证"检查语法错误。
  3. 3 点击"转换为JSON"查看JSON表示。
  4. 4 修复显示的错误——错误消息包含行号。

What YAML is and why indentation breaks it

YAML ("YAML Ain't Markup Language") is a human-readable data format used for configuration files almost everywhere — Docker Compose, Kubernetes, GitHub Actions, Ansible, and countless app settings. Its appeal is that it looks clean: no braces, no quotes most of the time, just keys, values, and structure expressed through indentation. That same strength is its biggest trap. Because YAML uses leading spaces to show nesting, a single misaligned space or a stray tab can completely change what your file means — or stop it from parsing at all. This validator reads your YAML, builds the same nested structure a parser would, and tells you whether it is well-formed, pointing to the line where it fails.

How the validator reads your file

The tool walks your YAML line by line. It first strips out blank lines and comments — including inline comments after a #, while being careful to leave a # alone when it sits inside a quoted string. For each remaining line it records the indentation depth, then assembles the data: a line like key: value becomes a mapping entry, a line starting with - becomes a list item, and deeper-indented lines become children of the line above. Scalar values are interpreted with their natural types, so true and yes become booleans, 30 becomes a number, ~ and null become null, and quoted text stays a string. If a line is indented inconsistently — claiming to be a child but not lining up with anything — the parser raises an error naming the offending line number.

A worked example

Consider this input:

YAMLParsed meaning
name: John Doestring "John Doe"
age: 30number 30
active: trueboolean true
tags:
  - admin
  - user
list ["admin", "user"]
address:
  city: Seoul
nested object {city: "Seoul"}

Press Convert to JSON and the tool emits the equivalent JSON, which makes the structure explicit with braces and brackets — useful both for confirming you got the nesting right and for feeding the data to a system that expects JSON. The age appears as a bare 30, not "30", confirming YAML inferred a number.

Use cases

  • Catching CI/CD failures before you push. A broken GitHub Actions or GitLab CI file fails the whole pipeline. Validating locally saves a round-trip of failed builds.
  • Debugging Kubernetes and Docker Compose manifests. These are deeply nested; one wrong indent on a volumes or env block silently drops settings.
  • Converting config to JSON. When an API or script wants JSON but your data lives in YAML, the converter gives you a clean translation.
  • Teaching and learning YAML. Seeing how indentation maps to objects and lists makes the rules concrete.

Common mistakes this catches

  • Tabs instead of spaces. YAML forbids tabs for indentation. They look identical to spaces in many editors but cause parse errors — set your editor to insert spaces.
  • Inconsistent nesting depth. If sibling keys are indented by different amounts, the structure becomes ambiguous. The validator flags the line where the indentation stops making sense.
  • Unquoted special values. A version number like 1.10 may be read as the number 1.1, and a country code like NO can become the boolean false. Quote values you intend to stay strings.
  • Forgetting the space after the colon. key:value is not a mapping; YAML needs key: value with a space. This is one of the most frequent typos.

Scope and privacy

This is a lightweight structural validator built for the common YAML you write by hand: mappings, lists, nested objects, scalars with type inference, and block text. It is not a full implementation of every corner of the YAML specification — exotic features like anchors, aliases, and multi-document streams are outside its scope — so for those, treat a clean result as a strong sanity check rather than a formal guarantee. Everything runs in your browser: your YAML is parsed locally and never uploaded, so it is safe to paste configuration that contains internal hostnames or settings.

常见问题

{# Alpine.js — self-hosted. (The previous jsdelivr CDN tag had a stale SRI integrity hash, so the browser refused to run it and window.Alpine was never defined — silently breaking every FAQ accordion and Alpine tool.) #}