Skip to main content

YAML formatter

Reindent YAML, normalize its presentation, and detect common structural issues directly in your browser.

  • Clipboard
  • Export
Automate

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Was this tool useful?

How does this tool work?

Reindent a YAML document without converting it to JSON. The formatter parses the structure before rewriting it, distinguishing mappings, lists and standalone text. It retains the document representation of comments, anchors and multiline values instead of rebuilding only their resolved values. Use it for versioned configuration or an excerpt you need to share with a team. Your file stays in the browser; processing does not access remote repositories or deployment services.

The parser defaults to YAML 1.2 and honors supported version directives. Once the document is recognized, serialization applies the chosen indentation, with a minimum of two spaces. Lists and mappings are identified syntactically rather than by replacing spaces on every line, which could alter literal string content.

Duplicate keys within a mapping, invalid syntax and multiple documents in one input are rejected. Tabs cannot indent YAML structure, although a tab may belong to a value depending on its syntax. A scalar such as not yaml is valid: YAML is not restricted to key/value pairs.

Formatting operates on the YAML document without expanding aliases into JSON objects. Anchors and comments can therefore remain represented. Large integers retain their spelling instead of passing through rounded JavaScript numbers. Presentation spaces, quotation styles and spacing inside compact collections may be normalized; output is not a byte-for-byte copy.

Success means this parser can read the document, not that your application accepts its settings. It does not load files named in configuration paths or interpret custom tags according to application rules. Older YAML consumers may also apply different typing rules, so check the version expected by your environment.

How to use this tool

  1. Import one YAML document

    Paste the complete text including comments. If a file contains multiple documents separated by ---, process each document individually.

  2. Choose indentation and format

    Select an offered width and run formatting. If it fails, check for an unclosed mapping, duplicate key or invalid structural indentation.

  3. Review and retrieve the file

    Compare multiline values and comments before copying or downloading YAML. Editing the source or indentation hides the previous result.

Use cases

Review configuration before a commit

Make indentation consistent to inspect nesting and comments. Layout alone cannot confirm parameter names or whether the target software accepts them.

Retain documented configuration

Prefer formatting over a JSON round trip when comments and anchor names help explain how a file works.

Separate syntax errors from contract errors

Check that YAML can be read, then validate application-specific requirements separately using your project’s own tooling.

Examples

Normalize valid indentation

Three spaces are valid indentation here. The default two-space width realigns child while retaining the note comment.

Input

# note
root:
   child: 1

Result

# note
root:
  child: 1

Retain a compact list

The parser recognizes items as a list and active as a boolean. Flow notation remains a list; only presentation spacing is normalized.

Input

items: [a, b]
active: true

Result

items: [ a, b ]
active: true

Tips and best practices

  • Do not globally replace spaces in YAML: they may belong to a text block whose exact value matters.
  • Quote strings resembling dates or booleans when different YAML consumers might interpret the same file differently.
  • Use JSON/YAML conversion when you need JSON. It performs additional checks for values that JSON can represent.
  • Keep useful directives and comments in your source copy and review the diff before replacing shared configuration.

Sources and references

Frequently asked questions

Why is plain text accepted as YAML?

YAML allows a scalar at the root. not yaml is a valid string even if a particular application requires a configuration object. Format syntax and application contracts are separate checks.

Will formatting remove comments and anchors?

The engine retains their representation in the YAML document rather than passing through JSON. Layout may change, but they are not deliberately discarded as they would be in a format without comments.

Does validation guarantee correct Kubernetes configuration?

No. Parsing checks the YAML document without knowing cluster resources, API versions or constraints. Follow it with the validations provided by your Kubernetes environment.

Why are duplicate keys rejected?

Readers may interpret repeated names differently. Rejecting them prompts you to choose the intended value or structure explicitly instead of silently losing one occurrence.

Related tools

Tools similar or complementary to this one.

Similar tools

Format, minify, and validate JSON to make it easier to read or more compact.

DevelopmentFeaturedUse this tool