The dump and dumps functions both accept an option called sort_keys, for example: json.dumps(data, sort_keys=True).