Skip to content

Instantly share code, notes, and snippets.

@FerusAndBeyond
Created April 20, 2022 18:15
Show Gist options
  • Save FerusAndBeyond/f93cf27c38f3a6708c09f5c20c17ebe7 to your computer and use it in GitHub Desktop.
Save FerusAndBeyond/f93cf27c38f3a6708c09f5c20c17ebe7 to your computer and use it in GitHub Desktop.
Dictionary to json
import json
a = dict(a=5, b=6)
# to json
json_string = json.dumps(a)
# json_string = '{"a": 5, "b": 6}'
# json to dict
assert a == json.loads(json_string)
# to json file
with open("dict.json", "w+") as f:
json.dump(a, f)
# from json file
with open("dict.json", "r") as f:
assert a == json.load(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment