I have a array as shown below:
[
{
"id":1,
"data": {1: 1, 2: 0, 4: 0}
},
{
"id":2,
"data": {1: 1, 2: 0, 4: 0}
}
]
I have another array as follows:
{
"id":1,
"measurementID": 55163,
"realData": [
{
"secondaryId": 7,
"measurementID": 55163,
"realDataId": 1,
"active": 1
},
{
"secondaryId": 8,
"measurementID": 55163,
"realDataId": 2,
"active": 0
}
]
},
{
"id":2,
"measurementID": 55163,
"realData": [
{
"secondaryId": 7,
"measurementID": 55163,
"realDataId": 1,
"active": 1
},
{
"secondaryId": 8,
"measurementID": 55163,
"realDataId": 2,
"active": 0
}
]
}
]
In this second array I have a array with name realData. I want to have this realData array in first array instead of data object. Movement will done on the basis of id. Element with a particular id will always be there in both array. I want to remove this data object from first array and move this realData array to first array with some modifications. Data object has folllowing format:
"data": {1: 1, 2: 1, 4: 0}
Left hand side is values matches with realDataId of realData array of second array. If this id matches then need to change value of active in readData array for that particular element with right hand side value of data object. For example, in realData array with realDataId as 2, it should see 2 is present in left hand side of a property in data object in first array and in data object 2 has value of 1, then I need to replace value of active to 1 because value of 2 in data object is 1 and need to do same for other elements. In case if a certain element is not there in realData array, then I need to add a element in realDataArray for that element. For example. in Data object for “4:0” element, we can see there is no element in realData array with id 4, then I need to add the element in realData array with realData id 4. Newly added element will look as follows:
{
"secondaryId": 0, ---> this will be always 0, if new element is getting added.
"measurementID": 55163, ---> value of this element need to be copied from measurementID of that particular element in realData array
"realDataId": 4, --> realDataId need to be set from data object for element "4:0". always left hand side value
"active": 0 --> Right hand side value of "4:0"
}


