0

I am sending a big json file from server to jade, but the " are replaced with: " therefor the json is unreadable/unparsable and I get this error:

Uncaught SyntaxError: Unexpected token & 

I send the data like this from node:

res.render(view, {world:{name:"SomeName",width:50},otherdata:{...}}); 

and then get it in jade like this:

doStuff(JSON.parse(#{data})); 

and here it is unreadable data which looks like:

{world:{name:"SomeName",width:50... 

can I somehow disable the conversion of the quotes?

3
  • More details ! this question is bad.. Commented Mar 15, 2015 at 0:42
  • @NetaMeta added in some more info Commented Mar 15, 2015 at 0:48
  • Why do you need to JSON.parse if the data is already an object? Commented Mar 15, 2015 at 0:56

2 Answers 2

1

Server side within your rout you will do the following consider the object user

var user = {username:"myname"}; res.locals.user = user ; 

response will be :

res.render('view'); 

jade view will have the variable available :

if user script(type='text/javascript'). var user = !{JSON.stringify(user)}; 

Try adding app.use(bodyParser.json()); if you still have the issue

hope that helps

Sign up to request clarification or add additional context in comments.

Comments

0

No experience with jade but from the language reference (http://jade-lang.com/reference/interpolation/) i guess

doStuff(JSON.parse(!{data})) 

might work

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.