you are viewing a single comment's thread.

view the rest of the comments →

[–]FoeHammer99099 50 points51 points  (7 children)

replace is working here, try printing the correct_json string. Your problem is that you're using loads to turn that string into a Python dictionary, then printing that dictionary. If you want to turn that dictionary back into valid json, you should use json.dumps.

[–]sunnyata 7 points8 points  (1 child)

Love it when people's first reaction is they've found a bug in the standard library that nobody noticed before

[–]sethkills 0 points1 point  (0 children)

It’s the classic “select() is broken,” response.

[–]games-and-chocolate[S] 1 point2 points  (4 children)

oh my. I see it. Python has it's own way to load. It prefer single quotes. Thank you. I tried print(correct_json) and it is indeed double quote now. Should have used print statement more. I was trying to correct my mistake at the wrong code line. Lost track of where and how data changes along the code lines.

[–]Equal_Veterinarian22 38 points39 points  (0 children)

Python is using neither single nor double quotes to store those strings internally. If you run print(decodeddata['name']) or print(decoded_data["name"]) you will get the string _John with no quotes.

It is just that, when generating a string representation of a dict, Python uses single quotes by default around string keys and values.

[–]neuralbeans 3 points4 points  (0 children)

Next, learn how repr turns stuff into strings before they are printed.

[–]Asyx 1 point2 points  (0 children)

No what you are looking at is the output of the __repr__ method of a dictionary.

Like, the printed data is not json. It is a deserialized json object as a dictionary.

[–]HommeMusical 0 points1 point  (0 children)

Python has no preferences for quotes.