Python parses json data with double quotation marks

advertisements

How do you parse json data with double quotes within:

json.loads('
{
"time":"1410661614",
"text":"This is great",
"from":
     {
      "username":"mrb",
      "id":"5071",
      "full_name":"Free "Mrb"" #here is the problem
     },
"id":"8090107"
}
')

python returns:

ValueError: Expecting ',' delimiter: line 1 column 107 (char 106)


You can easily fix this issue by escaping the double quote (\")

import json

json.loads("""

{
"time":"1410661614",
"text":"This is great",
"from":
     {
      "username":"mrb",
      "id":"5071",
      "full_name":"Free \\"Mrb\\""
     },
"id":"8090107"
}

""")

As said in the comments, better fix the json generator to properly escape the double quote, it will be hard to parse and correct the json file.