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.
CodePudding user response:
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 ''
CodePudding user response:
Expecting property name enclosed in double quotes
Let's understand this error, it simply says the property name has to be in double quotes. Now this refers to your JSON file since 00000 is not valid. If it was a number 0 would have been enough. But having 4 zeros is making it read it as a string
Strings in json need to be enclosed in double quotes
Change the json to:
{"guild_id" : "00000", "song_list" : []}
Hope it helps!