Чтобы красиво напечатать файл JSON на Python, вы можете использовать несколько методов. Вот несколько распространенных способов добиться этого:
Метод 1. Использование модуля json
import json
# Load the JSON data from a file or a string
json_data = ...
# Use the dumps() function with the indent parameter to pretty print the JSON
pretty_json = json.dumps(json_data, indent=4)
# Print or save the pretty printed JSON
print(pretty_json)
Метод 2: использование модуля pprint
import pprint
# Load the JSON data from a file or a string
json_data = ...
# Use the pprint() function to pretty print the JSON
pprint.pprint(json_data, indent=4)
Метод 3. Использование модуля json.tool(использование командной строки)
$ python -m json.tool <path_to_json_file>
В приведенных выше методах вы можете настроить параметр indent, чтобы указать желаемый уровень отступа.