Extracting Value using Javascript

I have one object with multiple strings(?) which in turn have an associated value.


25/02/2023, 12:50:39[node: debug 4](http://homeassistant.local:8123/api/hassio_ingress/Es9h_91l3om-pMJ8ebe--nzrVZnJhDX5XNOIMrFJH48/#)

msg.payload : Object

object

buildNumber: "56633"

currentConfigNumber: 1

diversityMode: 3

unitMode: 1

I am using he following script to try to extract one of the values

msg.payload = msg.payload.licenseMask.value

return msg;

But I get an error

msg.payload : undefined

undefined

Can anyone direct me to the correct code to get the value?

I don't see a property licenseMask in the example you posted.

My apoologies, I missed it off;

25/02/2023, 13:31:54node: debug 4
msg.payload : Object
object
buildNumber: "56633"
currentConfigNumber: 1
diversityMode: 3
unitMode: 1
licenseMask: "128851337727"
configName: "Config 1"

licenseMask has not got a property value. You want
msg.payload = msg.payload.licenseMask

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

Thanks Colin. I have read the page but for it just stops short of giving enough examples to make sense of. At least for someone with little experience like me.

So in the example on that page. I understand that the property is an object called msg.payload. But the bit I dont grasp is within that object, what are 'Firstname', 'Surname' and 'Age' referrred to as? Strings? And if 'Fred', 'Smith' and '28' are not values of those, what are they refered to as?

I am certain this is basic stuff for you guys but i'm clearly not understanding something very basic here.

Using the example you posted at the start, then licenseMask is a property of the object msg.payload, just as payload is a property of the object msg. So msg.payload.licenseMask has the value "128851337727". The quotes tell you that the type of the property is String, without the quotes it would be a Number.

To answer your question, in the link I posted, "Fred" is the value of the property msg.payload.firstName. Think of msg.payload.firstName as a heirarchical address, like town.street.house, and "Fred" is the what is stored in the house.

Does that help?

Yes, it does now I have reread your original comment.
When you said;

Blockquote
licenseMask has not got a property value
Blockquote

I was reading it as, LicenseMask does not have an associated value. But now I see you were saying there was no property called value in the object. Which is what I was mistakingly trying to do by using the code

msg.payload = msg.payload.licenseMask.value

Thanks that makes sense now.

Blockquote

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