Created
August 30, 2018 15:47
-
-
Save nukopy/c0d221c3c4e89f66f05dd804711964f1 to your computer and use it in GitHub Desktop.
Convert JSON file to Python dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import json | |
""" | |
explanation of json-module | |
json.load(file_obj) : file_obj --> dict | |
json.loads(json_str) : json_str --> dict | |
json.dumps(dict) : dict --> json_str | |
json.dump(dict, file_obj) : write variable-of-dict to JSON file | |
If json_file contains 2 or more objects, "json.load(file_obj)" will be to an error. | |
As JSON-file contains multiple objects, "json.load()" cannot extract 2 or more objects from JSON file at once. | |
""" | |
with open("output/top_cities_dic.json", mode="r", encoding="utf-8") as f: | |
dict = json.load(f) | |
for key in dict: | |
print(dict[key]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment