Valeriane Valeriane - 1 year ago 125
Javascript Question

Add item to JSON string

I create

object as:

var myJsonObject = JSON.stringify(objectString)

How I can add another item into

Answer Source

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