So, I have a lambda function which is called with, by an MQTT message in JSON. I am only attempting to log the values, and the top level dot fields work fine, but nested objects in the JSON are seen as "undefined". I also tried to JSON. stringify but in vain. Does anyone know how to fix this?
'use strict';
console.log('Loading function');
exports.handler = (event, context, callback) => {
console.log('Received event:', JSON.stringify(event, null, 2)); // Complete message
console.log('Received event.ApiVersion:',event.ApiVersion);
console.log('Received event.CollectionID:',event.CollectionId);
console.log('Received event.TagData.Time:',event.TagData.Time); //undefined
var TimeObj = {};
TimeObj = event.TagData.Time;
console.log('Received event TimeObj:',TimeObj); //undefined
};
Here are the cloud watch logs/results:
Loading function
Received event:
{
"FormatId": "TagValues",
"ApiVersion": 1,
"CollectionId": 2,
"TagData": [
{
"Time": "2017-09-02T11:06:35.917000+02:00",
"Values": {
"var1": 16777216,
"var2": 7534
}
}
]
}
Received event.ApiVersion: 1
Received event.CollectionID: 2
Received event.TagData.Time: undefined
Received event TimeObj: undefined