Node.js JSON.stringify() causing " in output. Can't parse with Jquery Node.js JSON.stringify() causing " in output. Can't parse with Jquery express express

Node.js JSON.stringify() causing " in output. Can't parse with Jquery


It's because when you call

    res.render('search_tags.jade', { locals: {        title: 'Search by Tags',        'pages': pages,        tagsJSON: JSON.stringify(tagsJSONObj) //pass the tags data as a JSON obj        }    });

search_tags.jade is meant to output HTML, so it encodes your quotes. You should use a renderer that doesn't HTML escape, or at least change your view so that your params aren't HTML encoded

If you don't want something in the output escaped, use !{tagsJSON} within the view. However, when outputting JSON, there's no need for a view. you can just take your object, call JSON.stringify. I don't use JADE so I'm not sure if there is a way to create view that can just call JSON.stringify(), but that's what I've done in JSP, velocity, ASP, PHP and Code Igniter (not using JSON.stringify, instead it uses a JSON tool for the given language)


in ejs, its <%- tagsJSON %>

          ^ <---- Note the "-"


Better solution when using Swig.js

{{ data|json|raw }}