0

How can I get the distance value and how to assign it to another variable. I get that data from bluemix (Watson IoT Platform) to node-red

{distance:"45.9"};

I tried like

var data=msg.distance;
amadain
  • 2,724
  • 4
  • 37
  • 58

2 Answers2

0

Use Json.parse to convert the string to an array.Now you can access the elements of the array.

aaditya
  • 555
  • 7
  • 19
0

If you include the JSON node it will convert your JS Object to JSON. But maybe you have messed with the quotes and actually have json; by default you would.

I would add a Debug node to your IoT-In node. Check what exactly you receive. And then it is usually easy to parse like (it depends on what you send):

var distance = msg.payload.d.distance 
var distance = msg.payload.distance

You might want to edit your Question to include exactly what you receive in the Debug node and need to parse.

Also be aware that your value for distance is a string, you'll probably want to convert it to a number at somepoint. If it is in your control, it would be better practice to send it as a number to start with.

amadain
  • 2,724
  • 4
  • 37
  • 58