I am passing one json string variable from nodejs to ejs.
e.g
stringJson = "{"obj" : "it's not working"}"
I am retrieving this value on ejs inside script tag using var stringifiedJson = '<%- stringJson%>'
so when page is being rendered it is giving error "SyntaxError: missing ; before statement" because stringJson value contain single quote.
I came across some solution like i can replace it single quote with "'" but problem in this solution i am passing many jsonString variables from node to ejs. so i have do same in all variables.
I also seen in some solution like below
<script>
var stringifiedJson = <%- stringJson%>
</script>
without surrounding ' '. but its showing error "expression require" error.
is there any other way with i can parse jsonString to Json object?
stringJson.obj: <%= stringJson.obj %>
This wont work because stringJson has to be parsed in json object. and i am doing operation in script tag. – Bhavin Hirpara Apr 06 '17 at 11:04