Reputation: 579
Tested in chrome, firefox, opera.
JSON.stringify([])
"[]"
The problem is ...
JSON.stringify([])
"[]"
but it is ""[]""
When I try to re-create the original object like this: JSON.parse(JSON.stringify([]))
on the first URL it is an array []
which is correct, but on the second one it is a string "[]"
.
My question is how to fix this. I want to get an array (correct result) on both URLs. Is this some bug in browser?
Thank you guys
Upvotes: 1
Views: 554
Reputation: 94359
It seems like the problem was that your page is using Prototype.js 1.6, which was from 10 years ago and it messes up your page's objects.
The problem was that Prototype.js adds .toJSON
to Array.prototype
which is very problematic (.toJSON
instructs JSON.stringify
how to serialize an object instance.) Remove that method and it should work fine.
delete Array.prototype.toJSON;
JSON.stringify([]);
Get rid of that library as soon as possible.
Upvotes: 1