how can i use the data i have in my json file to make the script work?

Question:

I’m recently learning python and I came across this exercise where I have to create a mail generator with the catchall, the latter must be inserted in an external json file, the only problem is that I can’t tell the program to use the catchall which is placed in the json file, can anyone help me?
Thanks in advance

this is part of code: need to fix email_format

for i in range (emails_number):
                letters_list = [string.digits, string.ascii_lowercase, string.ascii_uppercase]

                letters_list_to_str = "".join(letters_list)

                email_format = (json.data file)

                email_generated = "".join(random.choices(letters_list_to_str, k=chars)) + email_format

                print(email_generated)
email_gen()
Asked By: Riccardo

||

Answers:

If you want to open a json file in general, use:

import json
with open(jsonfilepath, "r") as f:
    data = json.load(f)

then you can access the information in the file like a dictionary:

email_format=data["catchall"]
Answered By: Dan
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.