Valeriane Valeriane - 8 months ago 68
Javascript Question

Add item to JSON string

I create

object as:

var myJsonObject = JSON.stringify(objectString)

How I can add another item into


myJsonObject is now a string you cannot add anything to it again until you change it back into a JSON object.

So you can technically do:

var myJsonObject = JSON.parse(myJsonObject); //change to obj
myJsonObject.somethingnew = true; //add something
myJsonObject = JSON.stringify(myJsonObject); //change back to string