I am struggling with a valid JSON generated using PHP like this:
var json = <?php echo json_encode(['somearray']); ?>
.
Inside the array, there is an HTML string as shown below:
$myArray = ['image' => '<img src="/img/files/icon3.png" alt="" title="" />'];
json_encode($myArray);
However, when I try to parse this JSON using JSON.parser, it keeps throwing an "Unexpected token" error message like this:
"SyntaxError: Unexpected token / in JSON at position XYZ"
For example, consider the following JSON data:
var json = '[{"id":8,"type":"dataFiles","name":"Noise Data Files","selected":{"data":{"id":1,"subscription_id":"3","filestorage_id":"1","title":"test 1","graph_type":"line chart","settings":{"band":"broadband","interval":"long","measurement":"1","time_interval":"","frequency":"","param":"","display":""},"created_at":"2018-07-03 21:46:08","updated_at":"2018-07-03 21:46:08","created_by":"5","page":"1","picture":"customers/3/dataviewer/nKvvMkRbKcU53mkflUdqIe8VUaRrM83EqpsiPNuc.png","pivot":{"project_element_id":"4","dataviewer_id":"1"},"type":"<img src=\"/img/dataviewer/icon.png\" alt=\"3\" title=\"Third\" />","name":"00014_C_110609_240118 (1).csv","instrument":"dBAir","serial_number":"67600","recorded_on":"2024-01-18 11:06:09"}},"set":true},{"id":2,"type":"freeText","name":"Free Text","selected":"Some text","set":true}]';
JSON.parse(json);