I have a standard JSON stored in a variable and am able to add a top level key when directly using text but a variable,
[{"myKey":"my value"}]
is stored in orginalJson. I then add a top level key as text
var newJson = JSON.parse(orginalJson);
newJson = { myText: newJson };
gives
{ "myText": [{"myKey":"my value"}]}
I would now like to replace the text in the code with a variable
var newVar = "newtext";
var newJson = JSON.parse(orginalJson);
newJson = { newVar: newJson };
however I do not get the var value as expected, just the name of var not the value
expecting
{ "newtext": [{"myKey":"my value"}]}
but get
{ "newVar ": [{"myKey":"my value"}]}
what is the correct way to use a var in this instance. I have read other posts suggesting using a push but I have not had any luck understanding the correct syntax.