Search code examples
javascriptjsonbackbone.js

Syntax error js object to json


Hello i'm using Backbone here i have an issue, my 'history' attribute will be

history = history + ' * ' + 'Attribute "used" modified from ' + !this.changed.used + ' to ' + this.changed.used + ' by ' + LOGGED_USER.get("fisrtName") + " " + LOGGED_USER.get("name") + ' the ' + (new Date());

But when i do

this.set("history", history);
var json = JSON.stringify(this.toJSON())

the json returned is kind of corrupted with \

Any idea ?


Solution

  • Because the " needs to be escaped in strings, it is not corrupted.

    { "key" : "I am \"valid\"" }