Getting Syntaxerror: Json Parse Error: Expected '}' When Trying To Convert A String Into Json Using Javascript
my code looks like this: var str = '[{u'total': '54', u'value': '54', u'label': u'14 Sep'}, {u'total': '58', u'value': '4', u'label': u'15 Sep'}, {u'total': '65', u'value': '7', u'
Solution 1:
If you cannot change this python dictionary, you can use a workaround:
var str = "[{u'total': '54', u'value': '54', u'label': u'14 Sep'}, {u'total': '58', u'value': '4', u'label': u'15 Sep'}, {u'total': '65', u'value': '7', u'label': u'16 Sep'}]";
str = str.replace(/u?'(.+?)': u?'(.+?)'/g, '"$1":"$2"');
console.log(str);
console.log(JSON.parse(str));
Post a Comment for "Getting Syntaxerror: Json Parse Error: Expected '}' When Trying To Convert A String Into Json Using Javascript"