I have a (probably malformed) string I need to convert to the json format. Printing out the string I get
{"composemsg":{"return":null,"report":"<p class=\"error j-table-ui-report-entry\">07:39:28 - Action failed<br\/>Error adding row 0<br\/> Message <span class=\"label\">\"Test Message\"<\/span>, Receivers 'Array\n(\n [0] => gaga7\n)\n'<br\/><\/p>",0:""}}
ADDED: I have no way to modify this string in the first place or to change the code that produces this string. All I have is the string as quoted above!
When trying to convert the string (contained in the variable ‘j’) using
json.loads(j)
I get an error:
ValueError: Expecting property name: line 1 column 250 (char 250)
However, when starting python on the command line and asserting a variable to the printed-out string (replacing ‘null’ by ‘None’), it works fine:
In [40]: x = {"composemsg":{"return":None,"report":"<p class=\"error j-table-ui-report-entry\">07:39:28 - Action failed<br\/>Error adding row 0<br\/> Message <span class=\"label\">\"Test Message\"<\/span>, Receivers 'Array\n(\n [0] => gaga7\n)\n'<br\/><\/p>",0:""}}
In [41]: x
Out[41]:
{'composemsg': {0: '','report': '<p class="error j-table-ui-report-entry">07:39:28 - Action failed<br\\/>Error adding row 0<br\\/> Message <span class="label">"Test Message<\\/span>, Receivers \'Array\n(\n [0] => gaga7\n)\n\'<br\\/><\\/p>', 'return': None}}
Any ideas of this behavior? Is there a malformed place in the original string? I do not see any issues.
JSON object property names should be strings. From http://www.json.org/:
The error message is pointing that you have an unquoted property name at the position 250 (the 0 key).
It may be hard to figure out because
{0:""}is valid both in Javascript and Python (but isn’t legal JSON).