YAML Formatter & Beautifier

Format and beautify YAML online, fix indentation errors, and convert YAML to JSON or JSON to YAML. Collapse to compact flow-style YAML, or validate structure with clear error messages.

Indent:
Copied
Input0 B
Output0 B

The library may still be loading — a short delay on the first click is normal. Click in the YAML and copy (Ctrl/Cmd+C) to copy the path at the caret (object►name►items).

What is YAML?

YAML ("YAML Ain't Markup Language") is a data serialisation format that uses indentation instead of brackets to show structure. The current version is YAML 1.2.2. It is the usual format for configuration in tools such as Docker Compose, Kubernetes, GitHub Actions and Ansible, because it is easy to read and supports comments. YAML 1.2 was designed so that JSON documents are also valid YAML, which is why this page can convert in both directions.

How to use the YAML formatter

  1. Paste YAML (or JSON) into the Input pane, or load it with File or URL (your browser fetches the address directly, so the remote server must allow cross-origin requests).
  2. Choose an Indent of 2 or 4 spaces. YAML does not allow tabs for indentation, so there is no tab option.
  3. Click Beautify, Minify (flow), YAML → JSON or JSON → YAML.
  4. Check the structure in Tree Viewer, then Copy or Download the result.

The page uses the open-source js-yaml library (version 4), loaded from cdn.jsdelivr.net. If you click a button before it has loaded, you will see "The YAML library has not loaded yet, please try again in a moment."

Buttons and options explained

What Beautify changes

Beautify parses your YAML into data and serialises that data again. It is not a whitespace-only reindent, so check these points before replacing a hand-written file:

Key order is preserved. For more on these behaviours, read YAML pitfalls: indentation, implicit types and multi-line strings.

Common errors and how to fix them

Errors are shown above the panes and in the Output pane. They include js-yaml's description, a few lines of context with a caret under the problem, and the line and column. JSON → YAML errors come from the browser's JSON parser instead.

MessageTypical causeFix
tab characters must not be used in indentationA tab at the start of a lineReplace tabs with spaces
bad indentation of a mapping entryA key indented differently from its siblings, or a second : on one line, as in key: value: otherLine sibling keys up; quote values that contain :
duplicated mapping keyThe same key twice in one mappingRemove or rename one of them
unexpected end of the stream within a double quoted scalarAn opening " with no closing quoteClose the quote
expected a single document in the stream, but found moreSeveral documents separated by ---Format each document on its own

Examples

InputActionOutput
name: api
tags:
- web
- prod
Beautify, 4 spacesname: api
tags:
    - web
    - prod
name: api
port: 8080
tags:
  - web
  - prod
Minify (flow){name: api, port: 8080, tags: [web, prod]}
name: api
port: 8080
tags:
  - web
  - prod
YAML → JSON, 2 spaces{
  "name": "api",
  "port": 8080,
  "tags": [
    "web",
    "prod"
  ]
}
version: 1.10
country: NO
mode: 0755
YAML → JSON"version": 1.1, "country": "NO", "mode": 755
base: &b
  a: 1
x:
  <<: *b
  c: 2
Beautifybase:
  a: 1
x:
  a: 1
  c: 2

The fourth row shows the YAML 1.2 core schema in action: NO stays a string (it was a boolean in YAML 1.1), and 0755 is read as the decimal number 755, not as an octal value. Write 0o755 for octal, or quote the value.

Frequently asked questions

Is my YAML sent to a server?

No. js-yaml is downloaded from cdn.jsdelivr.net, but parsing and formatting then run in your browser, and the page does not send your input anywhere. The URL button is the exception you control: your browser requests the address you type.

Why did my comments disappear?

Beautify, Minify and the converters work on the parsed data, and comments are not part of that data in js-yaml. If you need to keep comments, use the error messages here to find problems and fix the indentation by hand.

Can every JSON document be converted to YAML?

Yes. Anything JSON can express can be written as YAML, and JSON → YAML does exactly that. The reverse is not always lossless: comments, anchors and multiple documents have no JSON equivalent, and dates become strings.

What is flow style?

Flow style uses JSON-like brackets and braces, e.g. {key: value, list: [1, 2]}, instead of indentation-based block style. It is what Minify (flow) produces, and it is handy for short values inside a larger file.

Why does "yes" stay a string but 1.10 becomes 1.1?

js-yaml 4 follows the YAML 1.2 core schema, where only true, True, TRUE and the matching forms of false are booleans, so yes, no and on are strings. Numbers are still recognised, so 1.10 becomes the number 1.1. Quote version numbers.

Guides

Related tools