YAML Formatter and PyYAML Script Builder
Format YAML using the bundled parser, then generate Python formatting scripts.
Scope of this tool: Uses the bundled YAML parser to preserve parsed values. Formatting does not preserve comments or original scalar style. Script/settings generation remains available where provided.
Parser-backed YAML formatting preserves parsed values, not comments or original scalar style. Legacy tab-rewriting/compact options do not rewrite YAML values.
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?
The browser parses YAML with js-yaml and serializes the parsed values. Invalid syntax is rejected. Comments and original scalar quoting/style are not retained; use a round-trip parser when those details matter. Mapping order follows parser serialization rather than a line-by-line whitespace rewrite.
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 browser parses YAML with js-yaml and serializes the parsed values. Invalid syntax is rejected. Comments and original scalar quoting/style are not retained; use a round-trip parser when those details matter. Mapping order follows parser serialization rather than a line-by-line whitespace rewrite.
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?
The browser parses YAML with js-yaml and serializes the parsed values. Invalid syntax is rejected. Comments and original scalar quoting/style are not retained; use a round-trip parser when those details matter. Mapping order follows parser serialization rather than a line-by-line whitespace rewrite.
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?
The browser parses YAML with js-yaml and serializes the parsed values. Invalid syntax is rejected. Comments and original scalar quoting/style are not retained; use a round-trip parser when those details matter. Mapping order follows parser serialization rather than a line-by-line whitespace rewrite.
Continue your workflow
Browse related tools by task. Use the improved core tools for a consistent workspace with file import, downloads and clear validation errors.