YAML Formatter

Format, validate, and convert YAML documents with syntax highlighting and error detection

Runs locally

YAML Input

Formatted Output

Inspector

Paste valid YAML — structure, tree and key paths appear here automatically

Advanced Options

Compare with another YAML

Send this document to Data Diff and paste a second version to see what changed.

Validation with the exact error position

Validation runs on every keystroke using the js-yaml 1.2 parser. Valid documents get live counts of documents, mappings, sequences, keys and depth. Broken ones report the exact line and column, a probable cause, and a highlight at the failing position — not just "syntax error".

Common YAML errors this tool pinpoints

These mistakes account for most invalid YAML. Each one is detected with a position and a probable cause:

Bad indentation

A child line indented less than its parent, or siblings that do not align. Usually reported as "bad indentation of a mapping entry" at the exact line.

TAB character

YAML forbids tabs in indentation. The parser reports "found a tab character that violates indentation" and highlights the offending line.

Duplicate key

The same key twice in one mapping. js-yaml reports "duplicated mapping key" with the line of the second occurrence.

Missing colon or space

A key without a value ("key key2") or a colon glued to the key ("key:value" is a plain string, not a pair). Reported as "could not find expected ':'".

Before / After

Minified Kubernetes manifest on the left, the same document formatted with 2-space indent on the right. Structure, tree and paths update from the parsed document.

Before (flow style)
{apiVersion: apps/v1, kind: Deployment, metadata: {name: web-app}, spec: {replicas: 3, template: {metadata: {labels: {app: web}}}}}
After (block style)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: web

YAML quick reference (YAML 1.2)

  • Indentation is structure: spaces only — TAB characters are never allowed for indentation.
  • A colon must be followed by a space to be a key separator: "key: value", not "key:value".
  • Scalars resolve to types by the core schema: true/false (booleans), integers, floats, null (~ / null / empty). Note "yes"/"no" are plain strings in 1.2.
  • Multiple documents in one file are separated by a "---" line; "..." ends a document.
  • Anchors (&base) and aliases (*base) keep files DRY; merge keys ("<<: *base") inherit mappings.

Next steps with this data

Formatting is the first step. Continue the workflow without leaving your browser:

Frequently Asked Questions

Common questions about Yaml Formatter formatting answered

The formatter follows the YAML 1.2 specification, ensuring compatibility with modern tools like Kubernetes, Docker Compose, GitHub Actions, and other cloud-native platforms.

Yes, the bidirectional conversion feature lets you convert YAML to JSON and JSON to YAML while preserving data types, nested structures, and comments where applicable.

Absolutely. The formatter is designed to handle Kubernetes manifests, Docker Compose files, CI/CD pipelines, and other multi-document YAML files with proper section separation.

The validator checks indentation consistency, proper use of colons and dashes, quoted string balance, anchor and alias references, and provides line-specific error messages for quick debugging.

Yes, the formatter correctly handles YAML anchors (&), aliases (*), and merge keys (<<), preserving these DRY features while formatting the surrounding structure.

YAML 1.2, the current spec from yaml.org - the version Kubernetes, docker-compose, and GitHub Actions documents target. YAML 1.2 made JSON a valid subset and tightened boolean parsing; the formatter keeps your quoting explicit where 1.1 parsers (still common in Python PyYAML) would misread values like "no" or "0777".

YAML anchors, aliases, and block scalars carry comments through unchanged, but a comment attached to a key that gets re-indented moves with its indentation level. The formatter never deletes comments - it relocates them minimally to stay attached to the node they document.

It flags it: bare NO, no, ON, on, yes, n are quoted automatically during formatting, so YAML 1.1 parsers cannot coerce them to booleans. The country-code list [NO, SE, DK] stays three strings. YAML 1.2 only treats true/false as booleans, but quoting is the only output that is safe under both versions.

{-- * External Resources Component(#19 Phase 3b 内容佐证工程) * 工具页「权威引用」区块:RFC / W3C / WHATWG / ECMA / IANA / 官方规范站 / 官方语言文档 / Wikipedia。 * * - 接受 :slug 属性 → 经 config/tool-sources.php 家族矩阵渲染该工具的权威引用 * - slug 未命中映射时不渲染(无权威来源的工具静默跳过) * - 链接 title 保持英文(引用源专名);description 经 * common.resources.descriptions.{key} 本地化,lang 未命中回退英文(线上不裸奔) * - 链接保持 dofollow(rel="noopener noreferrer") * * @param string|null $slug --}}

Related Tools