I have a json file which contains this text:
{"_firstName": "John", "_lastName": "Baker", "_middleName": null, "_mobile": "7609984356", "_education": "Harvard", "_skills": null, "_email": "[email protected]"} I am trying to load it in to this Python object:
class Profile(): def __init__(self): self._firstName = None self._lastName = None self._middleName = None self._mobile = None self._education = None self._skills = [] self._email = None I am using:
def profileImport(self): with open("../tests/profile.json", "r") as f: self._prof.__dict__ = json.load(f) the line self._prof.__dict__ = json.load(f) is not properly loading the JSON data. I do not get an error from that line, but the object has all None types, indicating that the line didn't successfully load the json data. However, if I use json.loads(), I do get the valid json data as a string, which shows me that the proper file is being accessed. Why is self._prof.__dict__ = json.load(f) failing to parse the data into my object? I'm using Python 3.6.9.
prof = Profile(**json.load(f))self._prof?? Please provide a minimal reproducible exampleself._profis an instance of the Profile() class shown exactly how it is above. Meaning, thatself._profis an instance of that class with all fields set to None. I've passed a brand newProf()into the importer and calledprofileImport()on it.Profileobject, it works as expected.