json formatter terminal

# How to encode JSON as a string
import json
print(json.dumps({'a': 1, 'b': 2}) # '{ "a": 1, "b": 2 }'
print(json.dumps({'b': 1, 'a': 2}, sort_keys=True, indent=4))
# {
#    "a": 2,
#    "b": 1
# }

Here is what the above code is Doing:
1. json.dumps() takes a Python object and returns a string.
2. The sort_keys parameter is set to True to sort the keys in the output.
3. The indent parameter is set to 4 to make the output more readable.