Python: JSON File

Writing Python List in JSON File

import json
alphabet_letters = ["a", "b", "c"]

with open("alphabet_list.json", "w") as f:
  json.dump(alphabet_letters, f)

Writing Python Dictionary in JSON File

customer_29876 = {"first name": "David","last name": "Elliott",
                 "address": "4803 Wellesley St.", }

with open("customer_29876.json", "w") as f:
  json.dump(customer_29876, f)

Reading Data from JSON File

with open("customer_29876.json") as f:
   customer_29876 = json.load(f)

print(customer_29876)
print(customer_29876["last name"])