JSON Property Sorter

Sort all object keys alphabetically, recursively through nested objects.

Input
Output

How to Use JSON Sort

  1. Paste your JSON into the input panel on the left. This can be an API response, a configuration file, a package.json, or any valid JSON document.
  2. Click “Sort A→Z” to sort all object keys alphabetically at every level of nesting.
  3. Review the sorted output in the right panel. Keys are now in alphabetical order throughout the entire document, while array element order and all values remain unchanged.
  4. Copy the result using the copy button. The sorted JSON is ready to commit to version control, use in a diff comparison, or paste into your config file.
  5. Combine with other tools: Use the JSON Diff tool to compare the sorted output against another document, or the JSON Formatter to adjust indentation.

What is JSON Key Sorting?

JSON key sorting is the process of reordering the property names (keys) within every object in a JSON document into alphabetical order. According to the JSON specification, object keys are unordered — {"b":1,"a":2} and {"a":2,"b":1} are semantically identical. However, in practice, key order matters for readability, version control diffs, and deterministic output.

When two developers edit the same JSON config file and add properties in different positions, git diff shows noise from reordered keys mixed in with actual value changes. Sorting keys before committing eliminates this noise entirely. Sorted JSON also makes it easier to visually scan large objects — you can jump straight to the “d” section instead of hunting through randomly ordered properties. Tools like linters, hash-based caches, and snapshot tests benefit from deterministic key ordering as well. If you need to compare two JSON files after sorting, try the JSON Diff tool.

Examples

1. Sorting API response keys for consistent comparison

You receive two API responses that should be identical but have keys in different orders:

// Response A:
{
  "status": "ok",
  "count": 3,
  "data": { "z_field": true, "a_field": "hello" }
}

// Response B:
{
  "count": 3,
  "status": "ok",
  "data": { "a_field": "hello", "z_field": true }
}

After sorting both through this tool, the outputs are character-for-character identical — confirming the responses are semantically the same.

2. Sorting config before committing to Git

Your tsconfig.json has accumulated properties in random order over time:

{
  "compilerOptions": {
    "target": "ES2020",
    "strict": true,
    "module": "commonjs",
    "esModuleInterop": true,
    "outDir": "./dist",
    "baseUrl": ".",
    "declaration": true
  }
}

After sorting:

{
  "compilerOptions": {
    "baseUrl": ".",
    "declaration": true,
    "esModuleInterop": true,
    "module": "commonjs",
    "outDir": "./dist",
    "strict": true,
    "target": "ES2020"
  }
}

Now future edits produce clean, minimal diffs because every new property lands in its alphabetical position.

3. Sorting before diffing two configurations

Before comparing production and staging configs, sort both files first so that key-order differences do not pollute the diff. Paste each file here, copy the sorted output, then use the JSON Diff tool (or git diff) to see only the actual value differences.

// Production (unsorted):
{ "log_level": "warn", "db_pool": 20, "cache_ttl": 3600 }

// After sorting:
{ "cache_ttl": 3600, "db_pool": 20, "log_level": "warn" }

Common Use Cases

  • Clean version control diffs: Sort JSON config files before committing so that git diff shows only value changes, not key reordering noise.
  • Deterministic output: Produce consistent JSON output for snapshot tests, hash-based caching, or idempotent API responses.
  • Comparing API responses: Sort two responses before diffing to verify they are semantically identical regardless of key order.
  • Code review readability: Sorted configs are easier to review because reviewers can quickly locate properties by alphabetical position.
  • Linting and formatting: Many teams enforce sorted keys as a style rule in package.json, tsconfig.json, and .eslintrc.json.
  • Database exports: Sort JSON exports before storing or sharing so that consumers see a consistent structure regardless of the database’s internal ordering.
  • Schema alignment: When generating a JSON Schema or TypeScript interfaces, sorting the input first makes the generated output more readable.

Frequently Asked Questions

Does it sort keys recursively?

Yes. The tool sorts object keys alphabetically at every level of nesting — the root object, nested objects, objects inside arrays, and objects nested arbitrarily deep. Every object in the entire JSON tree has its keys sorted.

What about arrays — does it reorder array elements?

No. Array element order is preserved exactly as-is, because arrays in JSON are ordered by definition and reordering them would change the data’s meaning. Only object keys (which are unordered in the JSON specification) are sorted. However, if array elements are objects, their keys are sorted.

Does sorting change any values?

No. Sorting only changes the order of keys within objects. All values — strings, numbers, booleans, nulls, arrays, and nested objects — remain exactly the same. The output is semantically identical to the input; only the key ordering differs.

Why would I want to sort JSON keys?

Sorted keys make JSON deterministic and diffable. When keys are in a consistent order, comparing two JSON files with git diff or a diff tool shows only actual value changes — not noise from reordered keys. Sorted JSON is also easier to scan visually and is required by some tools for consistent hashing or caching.

How does it handle nested objects?

Nested objects are sorted independently at each level. A nested object’s keys are sorted alphabetically regardless of where it appears in the tree. This means the entire document has consistent key ordering from top to bottom.

Does it handle duplicate keys?

JSON does not officially support duplicate keys, and most parsers use the last value when duplicates exist. The sort tool parses the JSON using the browser’s JSON.parse(), which follows this behavior, and then sorts the resulting keys.

Is my data sent to a server?

No. All sorting happens entirely in your browser using JavaScript. Your JSON data never leaves your machine.

Privacy & How It Works

JSON Sort runs entirely in your browser. When you click Sort, the tool parses your JSON, recursively sorts all object keys alphabetically, and re-serializes the result with clean indentation — all using JavaScript running locally in your browser tab. No data is transmitted to any server, no cookies track your usage, and nothing is stored after you close the tab. This makes it safe to sort production configs, customer data exports, and files containing API keys or tokens. You can verify this by opening your browser’s Network tab. Other tools on JsonDevKit, including the JSON Formatter, JSON to YAML converter, and JSON Viewer, work the same way.