I have a nested JSON object given by
var data = {
"animal":
{
"canine": "dog",
"feline": "cat"
},
"bug": "beetle",
"carrot":
{
"color": "orange",
"type": "vegetable"
},
"population": 100
};
I have been trying to use JSON.stringify to store this information by
localStorage.setItem("myData", JSON.stringify(data));
but it does not store the nested parts of the JSON object. For example, it ignores it and instead shows
"animal":{}
How might I simply be able to resolve this issue? I have seen solutions involving modifying ajax to become synchronous, but I didn't really understand what was happening.
I just want it so that I can obtain in console
console.log(JSON.stringify(data))
//{"animal":{"canine":"dog","feline":"cat"},"bug":"beetle","carrot":{"color":"orange","type":"vegetable"},"population":100}
so if there is a method that does not use stringify, that will be great too.