I am getting a bit of headache just because a simple looking, easy statement is throwing some errors in my face.
I have a json file called strings.json like this:
In python 3, we can use below method.
Read from file and convert to JSON
import json
from pprint import pprint
# Considering "json_list.json" is a json file
with open('json_list.json') as fd:
json_data = json.load(fd)
pprint(json_data)
with statement automatically close the opened file descriptor.
String to JSON
import json
from pprint import pprint
json_data = json.loads('{"name" : "myName", "age":24}')
pprint(json_data)