EasyDeveloper

JSON Sorter

Sort JSON object keys recursively and optionally array values, ascending or descending.

Local ProcessingYour data stays in your browser. Nothing is uploaded.

Machine-generated JSON is usually emitted in a deterministic order, but hand-written config files and pasted API samples rarely are. Sorting the keys of a JSON document gives you a canonical, alphabetical layout that is far easier to read, diff and review. This tool sorts object keys recursively at every level, with an option to sort array values too.

Paste your JSON, choose ascending or descending, and press Sort. Every object in the document gets its keys reordered alphabetically - top-level, nested objects, and objects inside arrays alike. Values are left untouched, so the only thing that moves is the ordering of keys.

Optionally, arrays whose elements are all strings, numbers or booleans can be sorted as well, either ascending or descending. Arrays of objects are left alone to avoid destroying meaningful order. The result is returned pretty-printed so it is immediately usable.

All processing is local. Your JSON is parsed, sorted and formatted in your browser, and never leaves your machine.

Features

  • Sorts object keys alphabetically at every nesting depth, recursively.
  • Ascending and descending directions for both keys and array values.
  • Optional sorting of primitive arrays (strings, numbers, booleans, null).
  • Arrays of objects are preserved in their original order to keep meaning intact.
  • Pretty-printed output, two-space indentation, ready to paste back.
  • Handles mixed documents - objects, arrays, primitives - without error.
  • Fully offline; no upload, no account, no logs.

How to Use

  1. 1

    Paste your JSON

    Enter any valid JSON document - an object, an array, or a mix. The sorter accepts both formatted and minified input.

  2. 2

    Choose a direction

    Select Ascending for A-Z key order, or Descending for Z-A. The same direction applies to array values when sorting is enabled.

  3. 3

    Toggle array sorting

    Enable "Sort array values" if you want primitive arrays sorted too. Arrays of objects stay untouched regardless.

  4. 4

    Sort and copy

    Press Sort JSON, review the reordered document, and copy it back into your file or review.

Example

Nested keys sorted

{
  "z": { "b": 1, "a": 2 },
  "a": { "d": 4, "c": 3 }
}

{
  "a": { "c": 3, "d": 4 },
  "z": { "a": 2, "b": 1 }
}

Array sorted ascending

{
  "ports": [8080, 80, 443]
}

{
  "ports": [80, 443, 8080]
}

Common Problems

Sorting arrays of objects

An array of objects has no natural key order, and sorting it would destroy the original sequence that the data may depend on. The sorter leaves object arrays untouched and only sorts arrays of primitives when you enable the option.

Expecting sort to change the data

Sorting only reorders keys - values and their associations are preserved exactly. If the document contains a sequence that matters, key order is never semantic in JSON, so reordering is always safe for objects.

Mixed-type arrays

An array containing both numbers and strings is not sorted by default, because a reliable total order across types is ambiguous. Enable array sorting only when the elements are genuinely comparable.

Forgetting that JSON objects are unordered

JSON keys have no inherent order; order is a presentation choice. A sorter simply gives you a stable, conventional presentation - which makes diffs and reviews far easier than a random order.

Sorting in place for a mutable cache

If a system relies on a specific emitted order for caching or checksums, sorted output will change that order. Use sorted JSON for readability and review; keep the raw output for anything where byte-for-byte stability matters.

Hand-sorting large documents

Manual sorting of a large nested document is slow and error-prone. The tool reorders every level consistently in one pass, which a hand edit almost never does correctly.

Technical Details

Keys are compared lexicographically - uppercase letters sort before lowercase because their code points are lower. If you need case-insensitive order, normalize the document or convert keys first.

The sort is recursive: every object in the tree is processed, including objects nested inside arrays, so the entire document ends up in a single consistent order.

Array sorting compares primitives by their string form, which yields a stable order for strings, numbers and booleans in practice. Object arrays and mixed arrays are skipped to avoid meaningless reordering.

Output is re-serialized with JSON.stringify(value, null, 2), so the result is always valid, pretty-printed JSON ready to paste back into any tool.

Processing is local and synchronous. The document is parsed once, sorted in memory, and never transmitted.

Because sorting is deterministic, the same document plus the same options always produces the same output. That makes the tool useful for generating canonical, diff-stable JSON for code review and comparison pipelines.

Frequently Asked Questions

Does sorting change what my JSON means?

No. JSON objects are unordered by definition, so key order carries no meaning. Reordering keys never changes the data - it only changes how it is displayed.

Can I sort only the top level?

Not in this version - the sorter applies to every nesting level, which is what most users actually want. Sorting only the top level while leaving nested objects untouched is uncommon and easy to do by hand afterwards.

Why are arrays of objects not sorted?

Because there is no correct key to sort them by. A list of users could be ordered by id, name or join date depending on intent, and guessing wrong would corrupt the data. Primitive arrays have an unambiguous order, so those are safe to sort.

Will this upload my JSON?

No. The document is parsed and sorted entirely in your browser. Nothing is transmitted, stored or logged.

What about keys with special characters?

They sort like any other key, by their string value. Sorting only changes order, never the keys themselves, so quoted keys with spaces or symbols are preserved exactly.

Is the output minified or formatted?

Formatted with two-space indentation. If you need compact output after sorting, run the result through the JSON Minifier.

How are numbers and strings sorted together?

Lexicographically, by their string form. That keeps the order deterministic and predictable for mixed content. If you need numeric ordering, keep the values homogeneous and sort them first.

Will sorting break my JSON?

No. The tool re-serializes the result as valid JSON, and key order carries no meaning in the format - the sorted document parses to exactly the same data as the original.

Data & Privacy

Your data stays in your browser. Nothing is uploaded.

Processing
Local
Upload
None
Server Storage
None
Account
Not required