YAML

YAML Key Sorter

Sorts mapping keys alphabetically at every level, leaving sequence order alone, so two configurations can be diffed meaningfully.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the first configuration and sort it.
  2. Do the same with the second one.
  3. Diff the two sorted copies. What is left is a real difference in values rather than a difference in where somebody put a block.

What yaml key sorter does

Key order carries no meaning in a YAML mapping, but a diff tool does not know that. Two configurations that are identical in every value will produce pages of differences if somebody moved a block, and the one difference that matters is buried in the noise. Sorting both files first removes that noise entirely.

Sequence order is left exactly as it is, because there the order is data. The items of a list of steps, an argument list or a chain of middleware mean something in the order they were written, and sorting them would change what the file does rather than just how it reads.

Frequently asked questions

For mapping keys, yes — order carries no meaning in a YAML mapping and no loader depends on it. Sequence order is left untouched here precisely because there it does carry meaning.

Because a diff tool compares lines, not meaning. Two identical configurations produce pages of noise if somebody moved a block, and the one real difference hides in it. Sorting both copies first leaves only differences that matter.

No. Sorting means reading the document and writing it back out, so comments are lost the same way they are in the formatter. Sort throwaway copies for comparison and keep your committed file as it is.