i have dynamic data thats coming into my application, the data structure is the same but the name of the property name being reported on changes. I am trying to write a function that would accept the value of the property variable input to a function and assign it as a variable name.
In the code below, for the measurements variable I want the variable name 'tag' to be the value of the 'tagName' input for the fucntion. Appreciate any help i can get with this! Thankyou!
function iotcjson(device, tagName, value) {
var data = {
device: { deviceId: device },
measurements: { tag: value }
}
return data
}
Considering value of tagName
is "temperature"
Actual result:
{"device":{"deviceId":"device1"},"measurements"{"tag":11.2}}
Desired Result:
{"device":{"deviceId":"device1"},"measurements"{"temperature":11.2}}