Blog
Wild & Free Tools

Sort JSON Keys Without Python — Skip json.dumps sort_keys

Last updated: March 2026 6 min read
Quick Answer

Table of Contents

  1. The Python way
  2. Recursion gotcha
  3. Browser flow
  4. Comparison table
  5. Pair workflows
  6. Frequently Asked Questions

If your instinct is to open a Python REPL and run json.dumps(data, sort_keys=True, indent=2) every time you need alphabetized JSON, there is a faster way. Paste into our JSON Key Sorter, click Sort, done. No interpreter, no file I/O, no quoting issues with escaped characters on the command line.

This post is not anti-Python. json.dumps(sort_keys=True) is the right tool for scripts, pipelines, and anything that runs more than once. For "sort this JSON blob I just received," the browser is faster.

What You Avoid by Skipping Python

Here is the typical Python workflow:

import json

with open('data.json') as f:
    data = json.load(f)

sorted_json = json.dumps(data, sort_keys=True, indent=2)
print(sorted_json)

Or for a quick inline version:

python3 -c "import json,sys;print(json.dumps(json.load(sys.stdin),sort_keys=True,indent=2))" < data.json

Neither is long. Both have friction: saving the JSON to a file, opening a terminal, quoting the inline command correctly, dealing with shell escaping if the JSON has single quotes or backticks.

For a one-off, the browser skips all of that. Paste, click, copy. Total time: under 15 seconds.

sort_keys Is Recursive in json.dumps (But Not Everywhere)

Worth knowing: Python's json.dumps(sort_keys=True) IS recursive — it sorts keys at every nesting level. This matches what our browser tool does with recursive mode on.

However, some people use alternative libraries or write manual sort helpers that only sort the top level. Common variants that do NOT go deep:

# Top-level only — nested dicts stay as-is
sorted_top = dict(sorted(data.items()))

# Also top-level only
from collections import OrderedDict
sorted_top = OrderedDict(sorted(data.items()))

If you want guaranteed recursion with pure Python (without json.dumps), you have to write it yourself:

def sort_nested(obj):
    if isinstance(obj, dict):
        return {k: sort_nested(v) for k, v in sorted(obj.items())}
    if isinstance(obj, list):
        return [sort_nested(i) for i in obj]
    return obj

Our browser tool is recursive by default, with a checkbox to turn it off if you specifically want top-level-only sorting.

Sell Custom Apparel — We Handle Printing & Free Shipping

The Browser Flow

1. Open JSON Key Sorter.

2. Paste your JSON. It can be straight out of a Python print, a file, a clipboard, or an API response.

3. Confirm "Sort nested objects recursively" is checked.

4. Click Sort Keys.

5. Copy the result.

For data you are about to paste into a Python script anyway, this saves one round-trip. Instead of json.dumps-ing in Python, copying output, pasting somewhere, then processing — you sort it up front.

Side-by-Side Comparison

ScenarioPythonBrowser Tool
Sort a JSON blob on your clipboardPaste to file, run scriptPaste, click, done
Sort a large file on diskjson.dumps from fileOpen file, paste, sort, save
Sort JSON inside a scriptjson.dumps(sort_keys=True)Not applicable
Sort 1000 files in batchLoop with json.dumpsNot designed for it
Sort + validate in one shotjson.loads then json.dumpsInvalid JSON shows an error
Sort and commit to gitScript + git addSort, save, git add
Deal with trailing commas or Python single quotesExtra parsingStrict JSON only — fix first

Rule of thumb: if you will sort the same JSON more than three times, script it. Otherwise, use the browser.

Pair the Sorter With Other Browser Tools

Sorting rarely stands alone. Typical follow-up steps:

Format after sorting. The sorter outputs indented JSON, but if you want different indent or minification, pipe to JSON Formatter.

Flatten after sorting. Alphabetized nested JSON flattened with our JSON Flattener produces sorted dot-notation keys. Perfect for diff-friendly CSV export.

Compare after sorting. Sort two JSON blobs the same way, then paste both into our diff checker or code diff. Only real value differences show up.

Validate before sorting. If your JSON has syntax errors, the sorter will show an error. Check first with JSON Formatter & Validator if you are unsure.

This chain of tools replaces a lot of one-off Python scripts. The browser tab is faster for work you do once.

Sort JSON Without Opening Python

Paste, click Sort, copy the result. Recursive, alphabetical, no script.

Open Free JSON Key Sorter

Frequently Asked Questions

Does json.dumps(sort_keys=True) sort nested dicts?

Yes — Python json.dumps(sort_keys=True) recursively sorts keys at every nesting level. This matches our browser tool with recursion enabled. The confusion comes from hand-rolled sort helpers like dict(sorted(obj.items())) which only sort the top level.

Can I sort a JSON file from the command line without Python?

Yes — jq supports it: jq --sort-keys . input.json. But that requires jq installed, and jq has its own syntax quirks. For occasional sorting on a machine where jq is not installed, the browser tool has zero setup cost.

Does the browser tool handle Python-style single-quoted data?

No — it expects strict JSON with double quotes. If your data uses double-quoted keys and values, it works. If it looks like Python dict output with single quotes, you need to convert to real JSON first. The quickest conversion is a Python snippet: json.dumps(ast.literal_eval(your_string)).

How does this compare to using Prettier to sort keys?

Prettier does not sort keys by default — it preserves the order you wrote them. You can add a plugin (prettier-plugin-sort-json) or use a Prettier alternative that does. Our browser tool is faster for quick sorting; Prettier is better for enforcement via CI/pre-commit hooks.

Lauren Mitchell
Lauren Mitchell Privacy & Security Writer

Lauren spent four years as an IT security analyst translating complex security concepts for everyday users.

More articles by Lauren →
Launch Your Own Clothing Brand — No Inventory, No Risk