YAML Formatter

Format YAML documents.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Paste YAML and get it rewritten with clean two-space indentation and expanded flow style. Key order is preserved, but comments are lost because the document is parsed and re-serialised.

How to use

1
Step 1
Paste your YAML.
2
Step 2
Press Run.
3
Step 3
Copy the result, and re-add any comments you need.

How it works

The YAML is loaded into a data structure with js-yaml and dumped again with indent 2 and line width 100, without sorting keys. Inline maps like {k: v} are expanded into block style, and strings that YAML could misread (such as y or yes) are quoted.

Worked example

Messy indentation

Input
b: 2 a: - x - y c: {k: v}
Output
b: 2 a: - x - 'y' c: k: v
Walkthrough
Indentation is normalised, the flow map becomes a block, and y is quoted because it is a boolean in YAML 1.1.

Limitations

  • Comments are dropped, as are anchors and aliases (they are expanded).
  • Only a single document is supported.
  • Invalid YAML returns an error instead of formatted text.

Questions

How do I format YAML?
Paste it and press Run. The YAML is re-indented with two spaces.
Does it keep comments?
No. Comments are removed during formatting, so back up files that rely on them.
Does it sort keys?
No. Keys keep their original order.
Why was y quoted?
Some YAML parsers read bare y as a boolean, so the tool quotes it to be safe.

Features

  • Two-space indent
  • Key order kept
  • Syntax errors reported

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Learn JSON - Full Crash Course for Beginners

    freeCodeCamp.org

    Solid JSON syntax and nesting basics for formatter and validator tools.

    Watch on YouTube
  • Inspect Network Activity - Chrome DevTools 101

    Chrome for Developers

    Debugging payloads you paste into JSON and JWT tools.

    Watch on YouTube