There are several ways you can parse and print JSON data with a proper indentation in Python. You can use json module of Python to prettyprint a json data as shown in the below example –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import json json_data = '[{"name" : "debjeet"}, {"skills":["aws", "gcp", "azure"]}]' parsed = json.loads(json_data) ## or load from a file ## with open('filename.json', 'r') as handle: ## parsed = json.load(handle) print(json.dumps(parsed, indent=4, sort_keys=True)) ## Returns ## [ ## { ## "name": "debjeet" ## }, ## { ## "skills": [ ## "aws", ## "gcp", ## "azure" ## ] ## } ## ] |