# 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
# }
import json
# the json file where the output must be stored
out_file = open("myfile.json", "w")
json.dump(data, out_file)
out_file.close()
import json
# Creating a dictionary
Dictionary ={1:'Welcome', 2:'to',
3:'Geeks', 4:'for',
5:'Geeks'}
# Converts input dictionary into
# string and stores it in json_string
json_string = json.dumps(Dictionary)
print('Equivalent json string of input dictionary:',
json_string)
print(" ")
# Checking type of object
# returned by json.dumps
print(type(json_string))