Created
October 2, 2021 19:33
-
-
Save ProbonoBonobo/8633da8007019d4fba6a44598124d3d0 to your computer and use it in GitHub Desktop.
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 | |
# suppose we have a key:value mapping saved to "/tmp/my_obj.json". (Note: 'json' is a file serialization format that works in a similar way as Python `dict` objects) | |
# first, import the built-in `json` module | |
import json | |
with open("/tmp/my_obj.json", "r") as f: # open the file in "read" mode (indicated by the second argument, "r")... | |
my_obj = json.load(f) # and create a Python dictionary object `my_obj` from the key:value pairs in the file using the `json.load` function. | |
# you can preview the contents of my_obj by pretty-printing it like so: | |
print(json.dumps(my_obj, indent=4)) | |
# you can also access its keys... | |
print(my_obj.keys()) | |
# values... | |
for val in my_obj.values(): | |
print(val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment