I need to add an attribute that does not exist in the current JSON. The json object is as follows.
var jsonObj = {
"result" : "OK",
"data" : []
};
And I want to add the temperature inside the "data". I could do this as shown below.
jsonObj.data.push( {temperature : {}} );
And then, I want to add 'home', 'work' inside 'temperature'. The result will be as shown below.
{
"result" : "OK",
"data" : [
{ "temperature" : {
"home" : 24,
"work" : 20 } }
]
};
How can i do this? I managed to insert the "temperature" inside the "data", but could not add the "home" and "working" internal temperature. There may be more inside the "temperature", so it should be enclosed in {}.