Advertisements

headerup to 320x100 / 728x90

JSON Sorter

Recursively sort JSON object keys alphabetically while preserving array order

Input
Loading editor...
Output

Output will appear here...

Advertisements

content bottomup to 300x250

What is JSON Sorter

Last reviewed:

JSON (JavaScript Object Notation) is a lightweight, human-readable data format used almost everywhere on the web for APIs, config files, and log output.

JSON Sorter recursively walks through your JSON document and reorders every object's keys in alphabetical order, leaving array element order untouched.

It's a common prerequisite for producing canonical JSON used in hashing, signature verification, diffing, and source-control-friendly configuration files.

Why use it

  • Produce canonical JSON for hashing and signing.
  • Make source-controlled JSON diffs stable across teams.
  • Simplify manual review of large config files.
  • Feed predictable input into snapshot tests.
  • Teach students about deterministic serialisation.

Features

  • Recursive alphabetical key sort
  • Preserves array order
  • Emits two-space indented JSON
  • Validates input before sorting
  • Processes JSON Sorter locally in your browser, no upload required

How to use JSON Sorter

  1. Paste JSON. Drop any JSON document into the input.
  2. Click Sort. Every object's keys are reordered alphabetically.
  3. Copy result. Use the canonical JSON for signing, hashing, or diffs.

Example (before/after)

Unsorted JSON

{
  "name": "Ada",
  "id": 7,
  "roles": ["ops", "admin"]
}

Sorted JSON

{
  "id": 7,
  "name": "Ada",
  "roles": [
    "ops",
    "admin"
  ]
}

Common errors

Expected arrays to be sorted too

By default, arrays keep their original order.

Fix: Use a dedicated line sorter if you need array sorting as well.

Stable diffs across versions

Different serialisers may still emit different whitespace.

Fix: Use both JSON Sorter and the formatter to normalise output.

FAQ

Are arrays sorted too?

No — only object keys. Arrays preserve their original order so semantics are not changed.

Is sorting locale-aware?

It uses Array.sort's default string comparison (code-point order).

Is sort recursive?

Yes — every nested object is sorted.

Does it validate input?

Yes — invalid JSON returns an error message.

Is input uploaded?

No — sorting is client-side only.

Related tools

Pair the sorter with the fixer, cleaner, and formatter to produce canonical JSON. You can also browse the full Formatters & Beautifiers category for more options.

JSON Formatter

Format, validate, and beautify JSON online with readable indentation, syntax checking, and copy-ready output for APIs, logs, and config files.

JSON Fixer

Auto-repair common JSON errors — trailing commas, single quotes, unquoted keys, and comments

JSON Cleaner

Strip comments, null values, and empty strings to produce compact, production-ready JSON

JSON to One Line

Collapse formatted JSON into a single compact line — great for config files and env vars

JSON Navigator

Flatten any JSON document into a list of JSONPath-style leaf paths and values

JSON Validator

Validate JSON syntax and catch parse errors instantly. Paste JSON and get immediate feedback on structural issues, missing commas, and unquoted keys.

XML Sort

Sort sibling XML elements alphabetically by tag name while preserving attributes

Environment Variables Formatter

Format raw environment variables into clean .env, export, JSON, or YAML output with normalized quoting and copy-ready key ordering.

Angular Beautifier

Format Angular templates online with cleaner indentation and spacing for HTML, bindings, and interpolation blocks.

Babel Beautifier

Transform and reformat JavaScript code using Babel parsers. Supports modern JS features, JSX, and experimental syntax. Get cross-compatible formatted output.

C Beautifier

Format and beautify C code online with proper indentation and brace placement. Paste C code and get clean, readable output following standard C conventions.

C# Beautifier

Format and beautify C# code online with proper indentation and .NET coding style. Paste C# and get clean, readable output following best practices.