Reputation: 55
My code is as following, and x is already generated (function getting):
var y = JSON.stringify(x)
console.log(y)
return y
But when I go and try to print it on the screen (another function, below), I have this in the console:
"[{\"_id\":\"blabla\",\"header\":\"this is a test\",\"time\":\"2020/2/2 10:29:04 AM\",\"content\":\"test\",\"uniqueid\":\"bla\"},
The other function which is printing it:
var tasks = getJSON()
console.log('hello')
console.log(tasks[0].header)
What should I do to get rid of all the \ in the JSON?
Upvotes: 0
Views: 135
Reputation: 6971
This is normal actually and not a bug the \ is an escaped char that will be shown in the console.
So what is in the string is actually
"[{"_id":"blabla","header":"this is a test","time":"2020/2/2 10:29:04 AM","content":"test","uniqueid":"bla"},
when it gets spit out to the console it looks like
"[{\"_id\":\"blabla\",\"header\":\"this is a test\",\"time\":\"2020/2/2 10:29:04 AM\",\"content\":\"test\",\"uniqueid\":\"bla\"},
See https://www.freeformatter.com/ for more info
Upvotes: 3