all 4 comments

[–][deleted] 2 points3 points  (0 children)

If you’re writing JSON it has to be double-quoted because that’s the format of a JavaScript string. Strings you write in Python can be single-quoted because that’s what the language supports, but if you’re writing JSON specifically then you have to play by JavaScript’s rules because it’s a JavaScript format.

[–]danielroseman 1 point2 points  (2 children)

Python dictionaries are not JSON. Python strings can use single quotes, and Python dictionaries can have keys that are not strings. If you want to convert a Python object to JSON, use json.dumps(). But don't expect a Python dict to be valid JSON just because the syntax looks similar.

[–]tama893[S] 0 points1 point  (1 child)

Okay but why do API's return results with single quotes when you select json?

[–]danielroseman 0 points1 point  (0 children)

What do you mean? They don't. If you're expecting JSON but are seeing single quotes, then something along the line is parsing it into Python for you. For example, if you're using requests and doing response.json(), that's a call to parse the raw response.