My Code:
with open('music_queue.json', 'r') as f:
data = f.read()
list_str = data.split('\n')
print(list_str)
db = []
for d in list_str:
db.append(json.loads(d))
My raw JSON:
{"guild_id" : 00000, "song_list" : []}
I have tried doing:
data = data.replace('\"', '\\\"')
only for me to have this error:
Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
I’ve been at this for hours. What’s going on?
Also, apologies if this has already been answered. I literally couldn’t find anything here that I haven’t tried already.
>Solution :
Text inside json files must follow JSON standard and 00000 (without quotes to be marked as string) is not a valid value – replace it with 0 or "00000".
When you open a valid json file you can load the contents straight into a dictionary, like this:
with open('music_queue.json', 'r') as f:
data = json.load(f)
Example of valid json file:
{"guild_id" : 10000, "song_list" : []}
P.S. You have to use double quotes "" inside json files instead of single quotes ''