Python : PrettyPrint a OrderedDictionary

pprint is a very handy module for printing out objects in a humane form.

Unfortunately it doesnt prettyprint OrderedDict objects properly.

The following is a workaround for printing a OrderedDict object in a manner close to what pprint does for a regular dict

Use json module’s dumps method to print the OrderedDict

import json
od = <Your OrderedDict>
print(json.dumps(od, indent=4))