Skip to content

Instantly share code, notes, and snippets.

@Ricks-Lab
Created March 26, 2021 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ricks-Lab/8c300d35d24fd6515e361eb830c53144 to your computer and use it in GitHub Desktop.
Save Ricks-Lab/8c300d35d24fd6515e361eb830c53144 to your computer and use it in GitHub Desktop.
Pretty print a human readable and compliant json object from a dictionary
import pprint
import re
def json_pprint(json_dict: dict) -> None:
""" Print human readable and compliant json file from dict representation of json.
This solution solves the problem of quote differences between dict and json
"""
print(re.sub(r'\'', '\"',
pprint.pformat(json_dict, indent=2, width=120, sort_dicts=False)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment