I store JSON in a data attribute, which contains ":
<div id="tt" data-json='{"t":"title: "BB""}'></div>
I get the data-json value with jQuery:
aa1 = $('#tt').data('json');
However, I get a string aa1, not an object as I would expect. If I delete " from the JSON, then I get an object in aa1.
If I do so:
aa1_str = $('#tt').attr('data-json');
aa1 = JSON.parse(aa1_str);
I am getting an error in JSON.parse:
Uncaught SyntaxError: Unexpected token B in JSON at position 14
$('#tt').attr('data-json') returns an already parsed string, where " is replaced with ".
How can I correctly extract data from a JSON string which contains "?