-1

I am trying to read a dictionary from a JSON file which would look something like this.

{"@C": "C:\\Users\\user\\examplefolder}

I would like to load the dictionary from the file into filepath_dict. I am currently using this method to try this however, it refuses to load anything that is not a string.

import json


with open("filepaths.json", "r") as file:
    file.write(json.loads(filepaths_dict))

How can I load the JSON dictionary into a python one?

  • I missed the call; Fernando caught it. It loads only strings, because you called `json.loads` (load string). – Prune Feb 11 '21 at 00:12

1 Answers1

1

Use json.load

with open("filepaths.json", "r") as f:
    filepaths_dict = json.load(f)

json.loads: Will take a string

json.load: Will take a file

Also be careful about using the word "file" as a variable, you are overriding the built-in file function.