Parsing JSON data with hexadecimal values

I'm trying to parse a JSON value, the value is as follows :

{"ZbReceived":{"0xF063":{"Device":"0xF063","Name":"Sonoff_Motion_sensor","0500<00":"000000000000","ZoneStatusChange":0,"Occupancy":0,"Endpoint":1,"LinkQuality":45}}}

I'm interested in the value of Occupancy, and normally converting the result to JSON and then accessing the value as follows would work :

var newMsg = { payload: msg.payload.ZbReceived.0xF062.Occupancy };
return newMsg;

However, the above code gives an error of "Unexpected '.'."

What is the proper escape character in order to convince Node Red to behave as expected?

Thanks in advance.

I think you may need to put the message through the JSON node and then it may be more usable.

Oh, edit your post and use the </> button to post the message.

Makes it easier for others.

If you used the Microsoft alternate code editor instead of ACE, you would have seen the error :wink:

You can't have a plain property name that starts with a number. So to access that data, you need:

return {
    payload: msg.payload.ZbReceived["0xF063"].Occupancy
}

Thanks @TotallyInformation, that worked great ^^

The node red code ended up being :

if (msg.payload.ZbReceived['0xF062'].Device == '0xF062'){
    var newMsg = { payload: msg.payload.ZbReceived['0xF062'].Occupancy };
    return newMsg;   
} else {
    return null;
}

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.