Sort YAML keys

Sorting changes order, so it is its own operation — never part of formatting. Choose the scope and order, review the diff, and apply.

Default. true/false/null/ints/floats resolve per YAML 1.2.2 core; yes/no/on/off and dates stay strings.
Style options

Source

12 lines · rev 1

Paste or type YAML. Drop a file here to open it. Your source changes only when you apply a result.

Checking…Re-checking the latest source…

Preparing preview…

Download
Not editedNo preview yet.

What moves and what stays

Each key moves together with its value and the comments attached to it. << merge keys stay at the top of their mapping. Mappings with duplicate or complex keys are left in source order and reported. Sequences are never reordered.

The semantic check expects “equivalent, keys reordered”: every value, type and alias is the same, only order changed.

Questions

Can I sort only the top level?
Yes. Choose “Top level” to sort the document’s root mapping and leave nested mappings as they are.
What is natural order?
Natural order compares numbers inside keys by value, so item2 comes before item10.

Other tools