here slahses are used to exit charatcer " into your JSON encoded string (not a json object, because
> JSON.parse("{messages:1}") SyntaxError: Unexpected token m at Object.parse (native) at repl:1:7 at REPLServer.eval (repl.js:80:21) at Interface.<anonymous> (repl.js:182:12) at Interface.emit (events.js:67:17) at Interface._onLine (readline.js:162:10) at Interface._line (readline.js:426:8) at Interface._ttyWrite (readline.js:603:14) at ReadStream.<anonymous> (readline.js:82:12) at ReadStream.emit (events.js:88:20)
therefore, the keys must be enclosed in " to represent the string, but you cannot just put " inside the string. To fix this json parsers add \
> JSON.parse("{\"messages\":1}") { messages: 1 }
so when you parse just call JSON.Parse in the session line
> JSON.parse("{\"messages\":{\"cometchat\":{\"timedifference\":0,\"cometchat_buddytime\":0,\"msgavails\":\"\"}}}") { messages: { cometchat: { timedifference: 0, cometchat_buddytime: 0, msgavails: '' } } }
source share