I\'m thinking about embedding arbitrary JSON in the DOM like this:
HTML5 includes a element for keeping machine readable data. As a—perhaps safer—alternative to you could include your JSON data inside the value attribute of that element.
const jsonData = document.querySelector('.json-data');
const data = JSON.parse(jsonData.value);
console.log(data)
In this case you need to replace all single quotes with ' or with " if you opt to enclose the value with double quotes. Otherwise your risk XSS attacks like other answers have suggested.