Say I had the object:
var object = {
1: [2,5,"hi"],
hi: {hihi: 1}
};
How would I convert that to a string, and then back, preserving all the information? I would need this to work for a big object, with the values themselves being objects.
This is not a duplicate, the others didn't involve getting the object back.
Below is a live demo of how you can convert an object to a string and back using JSON.stringify() and JSON.parse().
Open your browser console and you can see that all attributes are preserved after the conversion to a string and back.
var object = {
1: [2,5,"hi"],
hi: {hihi: 1}
};
console.log(object);
var strobj = JSON.stringify(object);
console.log(strobj);
var unstrobj = JSON.parse(strobj);
console.log(unstrobj);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With