json:yaml

YAML formatter

Re-emit YAML in canonical block style with consistent indentation and quoting. Useful for files that several people and several tools have edited.

YAML
YAML

      
Paste YAML to convert.

Conversion happens in this browser tab. Nothing is uploaded, logged, or stored.

Normalising YAML

The formatter parses your YAML and re-emits it in canonical block style: consistent indentation, consistent quoting, flow collections expanded into block form. Use it when a file has been edited by several people and several tools and no longer has one coherent style.

One thing to know before you paste: comments are not preserved. The formatter parses to a data structure and writes it back out, and comments live outside that structure. If your file is documented — and a good values.yaml is — format a copy and re-apply the comments, or use a comment-preserving tool such as ruamel.yaml or prettier.

Before and after

Mixed style
name: checkout-api
resources: {cpu: 500m, memory: 512Mi}
env:
    - name: LOG_LEVEL
      value: 'info'
ports: [8080, 9090]
Normalised
name: checkout-api
resources:
  cpu: 500m
  memory: 512Mi
env:
  - name: LOG_LEVEL
    value: info
ports:
  - 8080
  - 9090

Flow style — the {} and [] forms — is valid YAML and stays valid. It is worth keeping for genuinely short values such as ports: [80, 443]. Block style wins as soon as a collection has more than two or three entries, or when reviewers need to comment on individual lines.

Conventions worth adopting

  • Two spaces per level. Four is legal but pushes deeply nested manifests off the right edge of a review pane.
  • Indent list items under their parent key. Both forms are valid, but the indented form is what Kubernetes, Ansible, and GitHub Actions examples use.
  • Never use tabs. They are forbidden in indentation and will fail to parse, as the indentation rules explain.
  • Use block scalars for anything with newlines in it, rather than escaping them into one long quoted line.
  • Quote anything ambiguous: version numbers, values that look like booleans, strings with a leading zero, anything containing a colon.
  • One document per file where you can. Multi-document files with --- separators are harder to tool around.
  • End the file with a single newline.

Formatting in your editor and CI

# Prettier — preserves comments, good for repositories
npx prettier --write '**/*.{yml,yaml}'

# yq — normalises structure, drops comments
yq -P -i '.' config.yaml

# yamllint — reports style problems rather than fixing them
yamllint -d '{extends: default, rules: {line-length: {max: 120}}}' .

For a repository, Prettier is usually the right choice because it keeps comments. Use yq for one-off normalisation of generated files.

Formatting happens locally

Files that need reformatting are files several people have edited, which in practice means Helm values, environment overlays, and deployment configs — the documents that hold connection strings and know every hostname in an estate.

The formatter never sees a network. It parses and re-emits your document inside this browser tab, and keeps no copy. If you would not paste a file into an unfamiliar web form, you can still paste it here, because there is no form and no endpoint.

Questions people ask

Are my comments preserved?
No. The formatter parses to a data structure and writes it back, and comments live outside that structure. For comment-preserving formatting use Prettier or ruamel.yaml.
What is the difference between block and flow style?
Flow style uses JSON-like braces and brackets on one line. Block style uses indentation and hyphens. Both are valid YAML; block style is what you want for anything a person will review line by line.
How many spaces should I indent?
Two. It is the convention across Kubernetes, Ansible, Docker Compose, and GitHub Actions, and it keeps nested files inside a readable width.
Will formatting change how my lists are indented?
Yes. Both list styles are valid YAML, and the formatter normalises to the indented form used across Kubernetes, Ansible and GitHub Actions documentation. If your repository has settled on the flush style, format a copy first and check the diff. The indentation rules explain the difference.
Why did my flow collections get expanded?
The formatter normalises to block style. If you want to keep short values like ports: [80, 443] inline, format only the sections you need rather than the whole file.