Sort JSON Keys Without Python — Skip json.dumps sort_keys
- Python json.dumps(sort_keys=True) only sorts top-level keys — recursion is not deep by default on every method.
- Our browser tool sorts recursively by default, in one click, without opening a Python REPL.
- When Python still wins: automated scripts, batch processing, integration with other data operations.
Table of Contents
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 ShippingThe 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
| Scenario | Python | Browser Tool |
|---|---|---|
| Sort a JSON blob on your clipboard | Paste to file, run script | Paste, click, done |
| Sort a large file on disk | json.dumps from file | Open file, paste, sort, save |
| Sort JSON inside a script | json.dumps(sort_keys=True) | Not applicable |
| Sort 1000 files in batch | Loop with json.dumps | Not designed for it |
| Sort + validate in one shot | json.loads then json.dumps | Invalid JSON shows an error |
| Sort and commit to git | Script + git add | Sort, save, git add |
| Deal with trailing commas or Python single quotes | Extra parsing | Strict 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 SorterFrequently 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.

