YAML Formatter & Validator Pro

Format, validate, and optimize YAML with enterprise-grade precision and real-time feedback

YAML Input

Formatted Output

Formatted Output

YAML Formatter & Validator Pro

Format, validate, and optimize YAML with enterprise-grade precision and real-time feedback

Features

  • YAML 1.2 syntax validation with line/column error reporting via js-yaml — pinpoint the exact bad indent or unquoted-special-character without binary searching
  • Pretty-print with configurable indent (2, 4, or tab) and choice of block or flow style for the output — block is what humans expect, flow is compact for transport
  • Sort keys alphabetically across all maps, optionally with depth limit — useful for normalizing config diffs so reviewers see real changes not key-order shuffles
  • Lossless round-trip through JS-Yaml: types (string/number/boolean/null/array/object/timestamp/binary) preserved, multi-document streams kept separate, tagged scalars handled per spec
  • Anchor and alias preservation toggle: keep `&name`/`*name` references intact (smaller output, harder to grep) or expand them inline (larger output, easier to diff)
  • Optional schema validation via Ajv when a $schema URI is referenced in the doc — same engine the JSON Schema Validator uses, with full Draft 2020-12 support
  • Copy and download buttons emit the formatted YAML ready to drop into a config repo, Kubernetes manifest, or CI pipeline file
  • Pure client-side: js-yaml + Ajv run in your browser, no upload happens. Works offline once cached, safe for secrets and proprietary configs

How to use

  1. Paste your YAML document into the input pane. The parser runs immediately — syntax errors show with line/column.
  2. Adjust indent (2/4/tab) and style (block or flow) to match your house format.
  3. Toggle sort keys if you want alphabetical normalization (helpful for reducing diff noise).
  4. Toggle expand anchors if reviewers struggle with `&name`/`*name` indirection.
  5. Click Format. The output pane updates with the cleaned YAML.
  6. Use Copy or Download to grab the result for committing or pasting into a manifest.

Tips & Best Practices

  • For Kubernetes manifests, run with indent=2 and sort-keys off (Kubernetes accepts both but `kubectl get -o yaml` produces 2-space block; matching it minimizes diff noise).
  • For Ansible playbooks, indent=2 + sort-keys off is conventional; sorting Ansible tasks alphabetically breaks task dependencies.
  • For docker-compose, indent=2 is universal; sort-keys helps when comparing two compose files for parity.
  • When converting YAML to JSON for API submission, use 2-space block then run JSON Formatter's minify on the resulting JSON.
  • Combine with JSON Schema Validator: write your schema in YAML for readability, format/validate here, convert to JSON, and feed to Ajv-based validators downstream.

FAQ

How does YAML 1.2 handle the Norway problem?

In YAML 1.1, `country: NO` was parsed as boolean false because `NO` was a yes/no literal. YAML 1.2 (the version js-yaml uses by default) restricted boolean literals to true/false and removed yes/no/on/off. Your existing YAML 1.1 files still parse with the right schema if you set the schema option; this tool uses the safer 1.2 default.

Why did my multi-document file get reordered?

Multi-document YAML (separated by `---`) is parsed as an array, formatted, then re-emitted in order. The order of documents is preserved; key order within documents is preserved unless you enabled sort-keys, in which case each document's top-level keys (and nested maps) are sorted alphabetically.

What happens to comments?

js-yaml's load+dump cycle strips comments — they're not part of the YAML node tree. If preserving comments is critical, use yaml (the eemeli/yaml package) instead, which has a separate Document API. This formatter prioritises validation and structural cleanup over comment preservation.

Does sort-keys break anchor references?

No — anchor names are part of the node, not the key. Sorting keys reorders the map entries but anchors and aliases still point to their original nodes. The output may look unusual (an anchor declared after its alias use) but loads correctly.

How is schema validation invoked?

If the document has a `$schema` URI at the top, Ajv loads that schema and validates the parsed YAML as if it were JSON. Validation errors include the JSON Pointer path to the violating node. Schemas without a $schema marker can be supplied via the secondary schema pane (when available).

Is anything sent to a server?

No. js-yaml parses locally; Ajv validates locally. The page makes no network calls when you click Format, no input is uploaded. Works offline once cached.

Can I format a file larger than my browser memory?

Practical limit ~50MB before the UI thread blocks noticeably. For larger files run a CLI yamllint + yq combo locally — this tool is optimised for human-edited config files, not log streams.

What about non-standard tags like !env or !secret?

Custom tags need a registered constructor in js-yaml. Without one, the parser errors. If your YAML uses templating placeholders, strip them before pasting, or pre-process with envsubst/sops/sealed-secrets first.