Open this example in the interactive library
Source code
import json
print(json.dumps({'b':2,'a':1}, sort_keys=True))Sample output
{"a": 1, "b": 2}
Encode sorted JSON. A self-contained example using the Python standard library.
Open this example in the interactive library
import json
print(json.dumps({'b':2,'a':1}, sort_keys=True)){"a": 1, "b": 2}