Squirrl Squirrl - 1 year ago 59
Javascript Question

How do I JSON.stringify( anObject ) without colons, backslashes, curly braces or quotes?

This is a simple sentence. I don't want anything <form><b>but</b></form> this.

But after some client-side html manipulation and...

var newBody = JSON.stringify(req.body);

followed by an update to MongoDb,

var update = { '$set' :{ 'body' : newBody} }

I have this:

body: '{"This is a simple sentence. I don\'t want anything <form><b>but</b></form> this. ":""}'

And when I convert it back to html it has curley braces and quotes, which exacerbate with each update. I looked here, and have tried escape back-slashes, but I can't figure it out. Thank you.

{"{\"This is a simple sentence. I <form><b>don't</b></form> want this. \":\"\"}"}

Answer Source

I believe JSON.stringify is unncessary, assuming you passed post parameters simpleSentance= 'I dont want anything <b>but</b> this'

var newBody = req.body.simpleSentance