sort_keys` parameter is used to specify whether the result of the JSON serialization should be sorted by keys or not. sort_keys` is set to `True`, the keys in the resulting JSON string will be sorted in alphabetical order. If `sort_keys` is set to `False` (which is the default value), the order of the keys in the resulting JSON string will not be guaranteed.sort_keys` parameter :import json
data = {
'name': 'John',
'age': 30,
'city': 'New York'
}
# serialize the dictionary to a JSON string with sorted keys
json_str = json.dumps(data, sort_keys=True)
# print the result
print(json_str){"age": 30, "city": "New York", "name": "John"}sort_keys` to `False`, the order of the keys in the JSON string will not be guaranteed :import json
data = {
'name': 'John',
'age': 30,
'city': 'New York'
}
# serialize the dictionary to a JSON string without sorted keys
json_str = json.dumps(data, sort_keys=False)
# print the result
print(json_str){"name": "John", "age": 30, "city": "New York"}