How to Use the JSON Module to Format JSON Data

import json

data = {'name': 'John', 'age': 30, 'city': 'New York'}
formatted_json = json.dumps(data, indent=2)
print(f"Original Data:\n{data}\nFormatted JSON:\n{formatted_json}")

Output:

Original Data:
{‘name’: ‘John’, ‘age’: 30, ‘city’: ‘New York’}
Formatted JSON:
{
“name”: “John”,
“age”: 30,
“city”: “New York”
}

Leave a Comment

Your email address will not be published.