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.
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
- 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).
- Choose an Indent of 2 or 4 spaces. YAML does not allow tabs for indentation, so there is no tab option.
- Click Beautify, Minify (flow), YAML → JSON or JSON → YAML.
- 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
- Beautify parses the YAML and writes it out again in block style with the chosen indent. Long lines are never wrapped, and block scalars (
|) stay as block scalars. - Minify (flow) writes the whole document in flow style on one line, for example
{name: api, port: 8080, tags: [web, prod]}. - YAML → JSON parses the YAML and prints JSON indented with 2 or 4 spaces.
- JSON → YAML parses the input as strict JSON and prints block-style YAML.
- Indent applies to Beautify, YAML → JSON and JSON → YAML.
- Tree Viewer shows the parsed data as a collapsible tree that follows the Input as you type. Clicking a node copies its path, such as
object►services►web►image. - Download saves the output as
formatted.yaml, or asconverted.jsonafter YAML → JSON.
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:
- Comments are removed. The parser does not keep them, so
# commentsdo not appear in the output. - Values are printed as the parser read them.
version: 1.10is a number and comes out as1.1; an unquoted date such as2024-01-01becomes2024-01-01T00:00:00.000Z. Quote values you want kept as text. - Quoting is normalised. Strings that would otherwise be read as another type keep quotes, in single-quote style:
q: "yes"becomesq: 'yes'. - Anchors and merge keys are rewritten. Merge keys (
<<: *base) are expanded into the merged keys, and anchors that are still shared are renamed to&ref_0,&ref_1and so on. - One document only. A file with several documents separated by
---is rejected with "expected a single document in the stream, but found more". Format each document separately.
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.
| Message | Typical cause | Fix |
|---|---|---|
| tab characters must not be used in indentation | A tab at the start of a line | Replace tabs with spaces |
| bad indentation of a mapping entry | A key indented differently from its siblings, or a second : on one line, as in key: value: other | Line sibling keys up; quote values that contain : |
| duplicated mapping key | The same key twice in one mapping | Remove or rename one of them |
| unexpected end of the stream within a double quoted scalar | An opening " with no closing quote | Close the quote |
| expected a single document in the stream, but found more | Several documents separated by --- | Format each document on its own |
Examples
| Input | Action | Output |
|---|---|---|
name: api | Beautify, 4 spaces | name: api |
name: api | Minify (flow) | {name: api, port: 8080, tags: [web, prod]} |
name: api | YAML → JSON, 2 spaces | { |
version: 1.10 | YAML → JSON | "version": 1.1, "country": "NO", "mode": 755 |
base: &b | Beautify | base: |
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
YAML Pitfalls: Indentation, Implicit Types and Multi-line Strings
The YAML mistakes that break configuration files: tabs, inconsistent indentation, values that change type, and block scalars.
JSON vs YAML vs XML: Differences and When to Use Each
How JSON, YAML and XML differ in syntax, data types, comments, schemas and tooling, and which to choose for APIs, configuration and documents.