JSON Sorter

Sort JSON keys alphabetically, sort arrays, or sort by a specific key

Shortcuts: Ctrl+Enter run · Ctrl+L clear · Ctrl+D download

Mode:

About JSON Sorter

JSON Sorter organizes your JSON data in a predictable order. You can sort all keys alphabetically throughout a document, sort arrays of primitives by value, or sort arrays of objects by a specific key. Sorted JSON is easier to diff, review, and maintain — especially useful for configuration files and data that is compared over time.

  • ✓Sort all object keys alphabetically throughout the entire document
  • ✓Sort arrays of strings or numbers by value (ascending or descending)
  • ✓Sort arrays of objects by a specified key
  • ✓Recursive key sorting — objects nested at any depth, including inside arrays, get sorted keys

Why and How to Sort JSON

The JSON specification says object keys are unordered, so {"b": 1, "a": 2} and {"a": 2, "b": 1} mean exactly the same thing. In practice, though, key order matters to humans and to tools that compare text. Two copies of the same config with keys in a different order produce a noisy diff, and finding one key in a large unsorted object takes longer than it should.

Sort modes

  • ·Keys A→Z and Keys Z→A sort the keys of every object, recursively, including objects nested inside arrays. Array order is never changed in these modes, because array order is meaningful.
  • ·Array ↑ and Array ↓ sort a top-level array of strings or numbers by value
  • ·By Key sorts a top-level array of objects by the value of one field you name, such as price or name, in ascending order

Example: normalizing a config before diffing

// Before
{ "version": 2, "name": "api", "env": { "PORT": "8080", "DEBUG": "false" } }

// Keys A→Z
{ "env": { "DEBUG": "false", "PORT": "8080" }, "name": "api", "version": 2 }

Sorting both versions of a file with Keys A→Z and then comparing them in the JSON Diff tool shows only the real changes, not differences caused by key order. This is the same idea behind canonical JSON formats used for signing and hashing documents.

Sorting arrays of objects

// By Key: price
[ { "sku": "B", "price": 30 }, { "sku": "A", "price": 5 } ]
→
[ { "sku": "A", "price": 5 }, { "sku": "B", "price": 30 } ]

Numbers are compared as numbers and strings alphabetically. Items whose field is missing or holds a different type than the others are not compared, so they may not end up where you expect — check mixed data after sorting.

Good to know

  • ·Sorting keys never changes what the data means; sorting arrays does, so only sort arrays where order is irrelevant
  • ·Uppercase and lowercase keys can sort differently than you expect — Keys A→Z uses raw character order, which puts uppercase letters before lowercase
  • ·Some tools rely on key order even though the spec does not guarantee it (for example, configs where the first key wins); check before committing a sorted file

Tip: Commit config files with sorted keys and your team will get smaller, cleaner pull request diffs.

Frequently Asked Questions

Ad