Skip to main content
Convert2JSON
Developer ToolsBrowser processing

YAML Formatter

Normalise the indentation of a YAML file — including one that has been edited by three different tools — while keeping the comments that explain it.

Input

YAML
characters
0
lines
0
size
0 B

Options

Your data stays on your device.Parsing, conversion and code generation happen in this browser. Input is not uploaded to Convert2JSON servers.Privacy policy

About this tool

YAML files accumulate inconsistent indentation faster than most formats, because the whitespace is both the syntax and the styling. A Helm chart or a CI config that several people have edited will typically have two-space blocks next to four-space blocks, and lists indented under their key in one place and level with it in another. All of it parses; none of it reads well.

Formatting here goes through the document tree rather than through a plain value, which is what makes it safe to run on a real config file: comments survive. A round trip that parsed to an object and re-emitted it would drop every comment in the file, and in a deployment manifest the comments are frequently the only documentation there is.

Multi-document streams are handled as streams. Every document between separators is formatted and all of them come back, which is the behaviour a Kubernetes manifest needs.

How to use this tool

  1. Paste YAML, or upload a .yaml or .yml file.

  2. Set the indent width and, if you want lines wrapped, a wrap column.

  3. Turn on "Sort keys alphabetically" if you want a stable order for diffing.

  4. Press Format, then copy or download the result.

Key features

  • Comments preserved, including trailing comments on a line
  • Every document in a multi-document stream formatted and returned
  • Configurable indent width and line-wrap column
  • Optional recursive alphabetical key sorting, leaving list order untouched
  • Anchors and aliases left intact rather than expanded
  • Indentation and tab errors reported with a line and a column

Example

Inconsistent indentation, comments kept

InputYAML

# billing service
service:   billing-api
image:
      repository: registry.example.test/billing
      tag: "2026.04.1"   # pinned

OutputYAML

# billing service
service: billing-api
image:
  repository: registry.example.test/billing
  tag: "2026.04.1" # pinned

Good to know

  • Sorting keys changes the file semantically for a reader even though the data is identical — in a config where order is a convention, it can make a diff harder to review rather than easier.
  • Quoting style is normalised by the emitter, so a value written in single quotes may come back in double quotes when that is the safer form.
  • A document using custom tags is formatted, but the tags are reproduced verbatim and are not interpreted.

Frequently asked questions

Will my comments survive?

Yes. That is the main reason this tool exists rather than telling you to convert to JSON and back. Comments attached to keys, to list items and at the end of a line are all kept.

What happens to a multi-document file?

All of it is formatted. Each document between separators is processed and the separators are put back, so a Kubernetes manifest with five resources comes back with five resources.

Why did my tabs cause an error?

YAML forbids tab characters for indentation because their displayed width is ambiguous. Replace leading tabs with spaces and the file will format.

Does sorting keys reorder my lists?

No. Only mapping keys are sorted. Sequence order is data in YAML, so reordering it would change the document rather than tidy it.

Your data stays on your device

Your data is processed locally in your browser and is not uploaded to our server. This page keeps working after you go offline, because there is nothing to send.