How to use
Use this tool to quickly clean up indentation and whitespace, then (optionally) export a Python formatter script.
- Paste your YAML into the input box.
- Select output indentation (2 or 4 spaces) and options like trailing-space cleanup.
- Click Format YAML and copy the result.
- Optional: click Generate Python script to format YAML files in your repo.
FAQ
Does this tool fully validate YAML?
No—this focuses on indentation/whitespace normalization and basic indentation sanity checks. For full YAML validation, parse it with ruamel.yaml or PyYAML in your environment.
Why does YAML fail when I use tabs?
YAML indentation is defined in spaces; tabs often break parsing or behave inconsistently across tools. Use spaces or enable the “Convert tabs to spaces” option.
Can it preserve comments and quotes exactly?
The web formatter only reindents lines; it does not parse YAML semantics. For true round-trip formatting that preserves comments/quotes, use the generated ruamel.yaml script.
What indentation should I use (2 or 4 spaces)?
2 spaces is the most common for YAML and tends to reduce diff noise; 4 can improve readability for deeply nested files. Pick one and keep it consistent.
Will it reorder keys or sort mappings like Python can?
No. This tool keeps your line order; sorting keys requires real YAML parsing and can change meaning in some workflows.
How do I format YAML files in my Python project automatically?
Generate the Python script, commit it to your repo, and run it in CI or pre-commit. Use ruamel.yaml if you want the best preservation of YAML structure.
Why do I get an “Inconsistent indentation” error?
Your file has lines whose leading spaces don’t align to the detected indent step (for example 2 spaces on one level and 3 on another). Fix the misaligned lines or reindent in an editor.