I'm struggling with a seemingly simple task of creating a JSON object. Despite my efforts, I can't seem to find the right information to guide me through it. Here is what I have so far:
var myJsonObject = new Object();
myJsonObject.context.applicationName = appName;
myJsonObject.context.ID = ID;
myJsonObject.context.domain = domain;
myJsonObject.context.production = "no";
myJsonObject.other.name = userName;
myJsonObject.other.date = userDate;
var myString = JSON.stringify(myJsonObject);
This is what I envision my JSON string should look like:
{
"context": {
"applicationName":"example",
"ID":"exampleID",
"domain":"someDomain",
"production","no"
},
"other": {
"name":"userName1",
"date":"userDate1"
}
}
Unfortunately, I keep encountering
myJsonObject.context is undefined
errors. I understand that this is due to not initializing it properly, but I'm at a loss on how to rectify this issue. Any guidance would be greatly appreciated.
I believe that myJsonObject.context needs to be initialized as another object before adding it to the original object as an array of objects. Is my assumption correct?