What it does
The YAML Formatter checks that YAML is valid and re-indents it consistently, keeping your comments. It handles files with several documents separated by ---, such as Kubernetes manifests, and can sort keys alphabetically.
How to use it
- Paste YAML into Input, or click Sample.
- Click Format.
- Choose 2 spaces or 4 spaces. YAML does not allow tabs for indentation, so Tab uses 2 spaces.
- Tick Sort keys to order keys alphabetically. Sorting rebuilds the document, so comments are dropped when it is on.
Example
app:
name: InTab # display name
debug: false
servers:
- host: alpha.local
port: 8080
Formatted with 2 spaces:
app:
name: InTab # display name
debug: false
servers:
- host: alpha.local
port: 8080
Good to know
- An error message gives the reason and position, such as a bad indent or a duplicate key.
- Indentation is meaningful in YAML. If a key ends up under the wrong parent, the formatter cannot guess what you meant, so check the structure.
- Common YAML traps:
no,yesandoncan be read as booleans by older parsers, and1.10can become the number 1.1. Quote values like these.
FAQ
Can it convert YAML to JSON? Yes, with the Data Format Converter or the JSON to YAML converter, which works in both directions.
Does it check a Kubernetes or Docker Compose schema? No. It checks YAML syntax only, not whether the fields are right for a particular tool.