How pretty print a JSON file in Python

Pretty printing a JSON file prints out its contents with proper spacing and indentation for readability.

Solution for How pretty print a JSON file in Python : You can use json.dumps() to pretty print a JSON file Call open(filename, mode) with “r” as mode to read filename as a stream. Load the data from the stream by calling json.load(stream) with the stream as stream. Call json.dumps(obj, indent=n) with obj as the loaded JSON to pretty print with n spaces per indent. Call close() to close the JSON file.


how-pretty-print-a-json-file-in-python