DevPik Logo

YAML Formatter Online

Format, validate, and minify YAML without losing comments, anchors or quoting, with line-precise error reporting that catches indentation mistakes and stray tabs, plus warnings for unquoted version strings, octal-looking numbers and dates. Customize indent size, sort keys, and toggle flow style.

Built and maintained by Muhammad Tayyab — Founder, DevPik.

Why Use YAML Formatter Online?

YAML is whitespace-sensitive and famously punishing: a single tab character or one space too many breaks the entire parse, often with a useless error message at line 87 of a 200-line file. This formatter surfaces errors with line and column precision, calls out tab characters before they bite you, and re-emits clean YAML in the indent style you choose without deleting your comments or expanding your anchors, so the result can go straight back into the repository. It also sorts keys deterministically, which keeps Kubernetes manifests, GitHub Actions workflows, and Helm values diff-friendly across edits. If you've ever spent 20 minutes hunting an invisible whitespace bug, this is the tool you wish you'd opened first.

How to Use YAML Formatter Online

  1. Choose Format, Validate, or Minify mode at the top of the toolbar.
  2. Paste your YAML into the left editor, drop a .yml or .yaml file onto it, or click Upload or Sample. Output appears on the right as you type.
  3. Customize formatting: indent size (2 or 4 spaces), sort keys alphabetically, and Flow short arrays, which puts lists of up to five plain values on one line.
  4. If your YAML is invalid, the tool shows the line and column of the first error with a hint about the usual cause. Valid YAML can still get an amber list of unquoted values that parsers read differently, such as 1.10, 0755 or a date.
  5. Click Copy or Download to save the formatted or minified YAML.

Worked Examples

Re-indent a messy CI workflow

Input
name: build
on:
   push:
      branches:
         - main # deploys from here
jobs:
  test:
     runs-on: ubuntu-latest
Output
name: build
on:
  push:
    branches:
      - main # deploys from here
jobs:
  test:
    runs-on: ubuntu-latest

Mixed 3- and 4-space indents normalized to consistent 2-space indentation. The comment stays on its line, and on: stays unquoted.

Validate Kubernetes manifest with bad indentation

Input
apiVersion: v1
kind: Pod
metadata:
  name: web
spec:
 containers:
   - name: nginx
      image: nginx:latest
Output
Line 7, column 12: Nested mappings are not allowed in compact mappings

Line 8 is indented one space further than name: on line 7, so the parser reads image: as a map nested inside the value nginx. Lining image: up with name: fixes it.

Minify a config for an environment variable

Input
host: localhost
port: 5432
user: admin
options:
  ssl: true
  pool: 10
Output
{host: localhost, port: 5432, user: admin, options: {ssl: true, pool: 10}}

Useful for embedding YAML in a single-line env var. It is still YAML rather than JSON, so strings stay unquoted.

About YAML Formatter Online

YAML is the configuration language of modern infrastructure, and it is also famously punishing: one stray tab character, one space too many, or one unquoted version string can break an entire Kubernetes manifest or CI workflow, often with an error message that points nowhere near the real problem. The YAML formatter takes messy or suspect YAML and re-emits it cleanly, validating as it goes. Only the layout changes: comments, anchors and aliases, custom tags such as CloudFormation's !Ref, and the way each value was quoted all come back as you wrote them, and numbers like 1.10 or 0755 are not rewritten. Paste your YAML into the editor or drop in a .yml/.yaml file, choose Format, Validate, or Minify mode, and the output appears in real time. The validator uses a spec-compliant parser and reports errors with exact line and column numbers, so instead of guessing where the missing colon is, you jump straight to it. Formatting options include indent size (2 or 4 spaces), alphabetical key sorting, and flow style for short arrays, which makes manifests diff-friendly across edits and reviews. Minify mode writes each document on a single line in flow style and drops the comments, handy when you need to embed a config snippet inside an environment variable or a single-line string. This tool is built for DevOps and platform engineers, GitHub Actions authors, Helm chart maintainers, and anyone who has ever lost twenty minutes to an invisible whitespace bug. A few practical notes. Tabs are forbidden in YAML: the formatter flags them before they bite you, and reformatting with spaces is the fix. Unquoted version strings are a classic trap: 1.10 parses as the number 1.1, so always quote versions like "1.10", and the formatter lists every one it finds with its line number, along with numbers that start with 0 and dates. Words like yes, no, on, and off become booleans in YAML 1.1 parsers, another reason to quote strings that look like them. Sorting keys never changes what a mapping means to a YAML parser, but leave it off where people read the order, such as the paths of an OpenAPI file. If your file parses in the validator but your application still rejects it, the mismatch is usually a schema problem (a wrong key name or type) rather than a syntax problem, and the formatted output makes that easier to spot.

Troubleshooting & Common Issues

I get 'bad indentation of a mapping entry' but the indentation looks fine

That message comes from js-yaml-based tools, and it means a key does not line up with the keys around it, often by a single space, or that a tab is hiding in the indentation. Paste the file here in Validate mode: the error gives the line and column, and an amber banner above the editor names the first line with a tab. Open the file in an editor with 'show invisibles' turned on and replace every tab with spaces. YAML forbids tabs as indentation entirely.

The string 'no' turned into false in my application

Your application's parser follows YAML 1.1, which reads yes, no, on, off, y and n as booleans: the so-called Norway problem, where the country code NO became false. YAML 1.2, which this tool uses, only treats true and false as booleans, and the formatter writes these words back exactly as you typed them, so it never changes them either way. Quote the value if it must be text in every parser: `country: "NO"`.

My multi-line string lost its line breaks

Use a block scalar indicator: `|` preserves line breaks, `>` folds them into spaces. Both can be followed by `-` (strip trailing newline) or `+` (keep all trailing newlines). Without an indicator, YAML treats your multi-line content as a single flowed string.

Sorting keys moved things I wanted in a set order

Key order never changes what a mapping means to a YAML parser, so sorted output loads to the same data, but people and some tools read the order. Swagger UI and Redoc list OpenAPI paths in file order, and conventions like name: first in a GitHub Actions step exist for readers. Leave 'Sort keys' off for those files. Lists are never reordered, so the steps of a job keep their sequence either way.

Frequently Asked Questions

Why does my YAML fail with a tab character error?

The YAML specification forbids tabs for indentation. Tabs are invisible and inconsistent across editors, which is why parsers reject them outright. Replace tabs with spaces (2 or 4, consistently), and the formatter will flag any remaining tabs for you.

Why did my version 1.10 become 1.1?

Unquoted scalars that look like numbers are parsed as numbers, so 1.10 becomes the float 1.1 in any program that loads the file. This formatter writes 1.10 back exactly as you typed it and lists it in the warnings with its line number, but quote any version-like string ("1.10") so every parser keeps it as text. The same applies to values like 3.10, numbers with a leading zero such as 0755, and dates that should stay strings.

Will formatting remove my comments?

No. Format keeps every comment, including ones at the end of a line, next to the line it belongs to, and Validate never changes anything. Minify is the exception: a single line has no room for comments, so it removes them.

Can formatting change any of my values?

No. Numbers, dates, booleans and plain words are written back exactly as typed, and quoted strings keep their quote style. The only rewrites are layout: a plain or folded value that spans several lines is joined onto one, an escape such as \u00e9 inside double quotes is written as the character itself, and a value with an explicit tag such as !!str 1.10 gains quotes. The data stays the same.

What is the difference between Validate and Format mode?

Validate checks whether your YAML is syntactically correct and reports errors with line and column numbers, without changing anything. Format validates and then re-emits clean, consistently indented YAML with your chosen options (indent size, sorted keys, flow style), keeping comments and anchors.

Can I use this as a YAML linter or checker?

For syntax, yes. Validate mode reports the first error with its line and column, rejects duplicate keys and aliases with no anchor, flags tab indentation and warns about unquoted values other parsers read differently. It does not apply yamllint style rules such as line length or document-start markers, and it does not check Kubernetes, Docker Compose or GitHub Actions schemas.

When would I use Minify mode?

Minify writes each document on one line in flow style, without comments, which is useful when embedding config inside environment variables, single-line strings, or size-constrained fields. Values and anchors are kept and | or > block strings become double-quoted strings with the same text. The result is still valid YAML and can be reformatted back at any time.

Does it handle several documents in one file?

Yes. Documents separated by --- are formatted one by one with the same options and joined with --- again, comments included, and Validate mode tells you how many documents it found.

Does sorting keys break my configuration?

Not for a YAML parser: a mapping's key order carries no meaning, so sorted output loads to exactly the same data, and lists are never reordered. Some tools show keys in file order, though, such as Swagger UI and Redoc listing OpenAPI paths, so leave Sort keys off where the order is for readers. A comment at the very top of the file stays at the top.

Are anchors and merge keys preserved?

Yes. Anchors (&), aliases (*) and merge keys (<<) are written back where they were, in Format and Minify alike, so shared blocks stay shared. An alias with no matching anchor above it is reported as an error, since every YAML loader would reject it.

Is my YAML data sent to a server?

No. Parsing and formatting happen entirely in your browser. Manifests often contain internal hostnames and secrets, so keeping them local is a deliberate design choice.

Guides & Further Reading

Related Tools

Was this tool helpful?