Let's say I have a string that looks like this:
"{'apple': 1, 'orange': 2}"
How can I determine if this is a valid json object? json.loads() doesn't work because the string uses single quotes instead of double. Replacing all single quotes with doubles quotes seems risky in the off chance a single quote is escaped, like this:
"{'sentence':'let\'s solve the issue'}"
Replace all single quotes with double quotes makes the sentence: let"s solve the issue, which is not correct.
I tried demjson, https://pypi.org/project/demjson/, and it worked, but it was incredibly slow. Any ideas?
how can I check if a string is a valid json" - ifjson.loads()throws an exception it's not valid JSON. Simple as that.