I want to save JSON-data to a (before not existing) file using the following code, which works with Python 3.6.5:
with open("Samples\\{}.json".format(id), "w", encoding="utf-8") as f:
json.dump(labels, f, ensure_ascii=False, indent=4)
This will create a new .json file in the folder Samples.
Now I tried the same with Python 3.7.3, but instead of creating a new .json file in said directory, it creates a file with a name like "Samples\xyz.json" in the directory the python code is running (running in a jupyter notebook).
I tried the following already, but it results in the same problem creating a file with the directory as file name:
f = open(os.path.expanduser(os.path.join("Samples/{}.json".format(document_id)))
json.dump(labels, f, ensure_ascii=False, indent=4)
How can I create a new .json file in the desired directory with Python 3.7.3?
joinincorrectly.. it should be join('Examples', '{}.json'.format(doc))