I have a dictionary that I submit to the API, and unfortunately the API requires the dictionary to be in a very specific order. I am loading a dictionary from a file.
Right now, he json.load(fh, object_pairs_hook=OrderedDict)
does exactly what he needs and orders the top-level keys in alphabetical order, but I need the dictionary to be ordered differently.
Specific order:
{
"kind": "string",
"apiVersion": "string",
"metadata": {...},
"spec": {
"subKey": "string"
}
}
How to specify the dictionary order of the upper and lower level keys with dictionaries loaded from a file?
source
share