YAML prettify and format
Prettify your YAML string into a friendly, human-readable format.
About YAML prettify and format
Re-formats a YAML document with consistent indentation, optionally sorting the keys of every mapping. The document is parsed and written back, so the output is valid, canonical YAML.
When you would use it
- Normalising the indentation of a configuration file edited by several people or tools.
- Sorting keys so two YAML files can be compared with a plain diff.
- Validating a YAML file: syntax errors are reported instead of formatted output.
How to use it
- Paste the YAML into the input field.
- Set the indent size (1 to 10 spaces) and toggle "Sort keys".
- Copy the formatted output.
Things worth knowing
- Because the document is parsed and re-serialised, comments are removed, anchors and aliases are expanded, and the original quoting style of strings may change. Values and structure stay identical.
- "Sort keys" reorders mappings alphabetically at every level. Lists keep their order, since order in a list is meaningful.
- Strings that would be read as another type (true, 1.0, null) are quoted in the output so their meaning is preserved.
- Only one document is handled; a file with several documents separated by --- is rejected.
Frequently asked questions
- Why did my comments disappear?
- YAML comments are not part of the data model, and the formatter works on the parsed data. Keep a copy of the original if the comments matter, or re-add them after formatting.
- Is this the same as the YAML to JSON converter?
- They share the parser, but this tool writes YAML back out while the converter writes JSON. Use this one when the result must stay YAML.