From what I heard, rendering data into scripts is bad practice. I would think that this is a problem with what you are experiencing. A potentially better option would be to use #{JSON.stringify(person)} and then JSON.parse() this with JSON.parse() on the client side. This way, you donβt have to worry about which characters are in your person object, as the JSON object takes care of this for you.
html head title Person Details body input(type="hidden", name="person", value="#{JSON.stringify(person)}") script var Person = function () { var _person = document.querySelectorAll('input[name="person"]').value; _person = JSON.parse(_person); for (var key in _person) { this[key] = _person[key]; }; };
...
Semantically, I would put it in an input tag, which is really strange, who knows. Ideally, I think you should do XMLHttpRequest when the page loads and uses JSON as the content-type , so you don't do anything funky.
source share