If you need any assistance, please contact the library staff at the Georgia Tech Library Help website.
JSON is very similar to a nested Python dictionary. However, here are some key differences:
The loads method parses a string of JSON code and turns it into a Python dictionary
jsonstring2dict = json.loads(‘jsonstring’)
The load method translates the data in a JSON file into a Python dictionary.
with open(‘jsonfilename.json’, ‘r’) as f:
json2dict = json.load(f)
We have a JSON string we are attempting to read in and convert to a Python Dictionary.
Output (a Python Dictionary):
Here, we have a JSON file we wish to convert into a Python dictionary.
There are two steps to read in a JSON file:
In Python, we can do both of these steps at once like this:
Output (Python Dictionary):
Two methods from the JSON module are used for writing JSON data.
dict2jsonstring = json.dumps(the_dict)
with open(‘file_out.json’, ‘w’) as f
json.dump(output_dict, f)
We have a Python Dictionary we are attempting to write to a JSON string.
Output (a JSON string):
Here, we have a Python Dictionary that we wish to write to a JSON file.
Again, there are 2 steps:
Output (JSON file):