By definition the JSON string is wrapped with double quote.
In fact:
json.loads('{"v":1}') #works
json.loads("{'v':1}") #doesn't work
But how to deal with the second statements?
I’m looking for a solution different from eval or replace.
Thanks.
Not sure if I got your requirements right, but are you looking for something like this?
Example usage:
EDIT: it seems that the humour I tried to have in making the example above is not self-explanatory. So, here’s another example:
This examples show how the “replacement” only happens at the extremities of the string, not within it.
you could also achieve the same with a regular expression, of course, but if you are just checking the starting and finishing char of a string, I find using regular string indexes more readable….