# Separating Object/Payload help (Solved) Thank you all

**URL:** <https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318>\
**Category:** General\
**Created:** [18 April 2019 03:20 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318 "2019-04-18T03:20:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [18 April 2019 03:20 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/1 "2019-04-18T03:20:41Z")

</div>

I have a python script running in a shell node. It works great but I can't figure out how to use the data that I'm getting this is the output in debug

```auto
RTD ADC Code: 7627
PT100 Resistance: 100.085754 ohms
Straight Line Approx. Temp: -17.656250 degC
Callendar-Van Dusen Temp (degC > 0): 0.219423 degC
high fault threshold: 32767
low fault threshold: 0

```

I've added the returns, it comes out as a long line with return arrows.  
The only number I need is the Callendar-Van Dusen Temp shown above as 0.219423. How do I pull that single value from the long string?

Thank you in advance!

This is a straight paste from the debug window-

````auto
RTD ADC Code: 7627PT100 Resistance: 100.085754 ohmsStraight Line Approx. Temp: -17.656250 degCCallendar-Van Dusen Temp (degC > 0): 0.219423 degChigh fault threshold: 32767low fault threshold: 0```

````

I've tried to use the splitter, it breaks the message into separate strings but the entire output is in quotes so I'm not sure how to manipulate that.  
Here is output after using the split node on it

```auto
Callendar-Van Dusen Temp (degC > 0): 0.219423 degC

```

Again all I would like to use in the number in the above string

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 April 2019 05:23 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/2 "2019-04-18T05:23:07Z")

</div>

Please mark your previous topic as solved.

Now you have the data. Would be best if you would change the source code into json and only `print` what you need. But ok; you can split it again by `:` then you will get the value (including the text behind it)

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [18 April 2019 13:42 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/3 "2019-04-18T13:42:32Z")

</div>

Bakman2  
Could you please be more specific? Perhaps an example, I'm very sorry but I don't understand how to do what you just described.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 April 2019 14:27 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/4 "2019-04-18T14:27:48Z")

</div>

Try this flow:

```auto
[{"id":"9d9035e6.34b128","type":"inject","z":"811bc2a8.14b62","name":"","topic":"","payload":"{\"payload\":\"RTD ADC Code: 7627\\n PT100 Resistance: 100.085754 ohms\\n Straight Line Approx. Temp: -17.656250 degC\\n Callendar-Van Dusen Temp (degC > 0): 0.219423 degC\\n high fault threshold: 32767\\n low fault threshold: 0\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":700,"wires":[["1203231e.4c0445"]]},{"id":"13240cc4.beedeb","type":"debug","z":"811bc2a8.14b62","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":410,"y":700,"wires":[]},{"id":"1203231e.4c0445","type":"function","z":"811bc2a8.14b62","name":"","func":"\np = msg.payload.payload\nrow = p.split(/\\r?\\n/)\n\noutput = {}\n\nfor(x=0;x<row.length;x++){\n input = row[x].split(\":\")\n output[input[0]] = parseFloat(input[1].trim()); \n}\n\nreturn {payload:output};","outputs":1,"noerr":0,"x":250,"y":700,"wires":[["13240cc4.beedeb"]]}]

```

Note, in the function node it states `msg.payload.payload` due to the use of the inject node. Change it to `msg.payload` and connect your python output to it.

I have removed the units and formatted them to floating numbers.

 ![21](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/ed5f910164caeff15b06b21158eddb3c33d77b67.jpeg)

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [18 April 2019 14:58 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/5 "2019-04-18T14:58:44Z")

</div>

Wow! Thank you very much! I changed to a singe payload and this is the output, I have no idea why this isn't working. That output looks great though. Any suggestions for how to make it look like yours?

```auto
[{"id":"729eef08.31b0d8","type":"pythonshell in","z":"1767a230.5f57b6","name":"Temp working rev 1","pyfile":"/home/pi/MAX31865/max31865.py","virtualenv":"","continuous":true,"stdInData":false,"x":250,"y":200,"wires":[["d6433b43.79d188","7eb2656d.f81d0c"]]},{"id":"160bd057.11d498","type":"debug","z":"1767a230.5f57b6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":200,"wires":[]},{"id":"d6433b43.79d188","type":"function","z":"1767a230.5f57b6","name":"bakman2","func":"\np = msg.payload\nrow = p.split(/\\r?\\n/)\n\noutput = {}\n\nfor(x=0;x<row.length;x++){\n input = row[x].split(\":\")\n output[input[0]] = parseFloat(input[1].trim()); \n}\n\nreturn {payload:output};","outputs":1,"noerr":0,"x":460,"y":200,"wires":[["160bd057.11d498"]]},{"id":"7eb2656d.f81d0c","type":"debug","z":"1767a230.5f57b6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":460,"y":260,"wires":[]}]

```

 ![48%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4417131a87b9c1f8f10803cb0268a5228a44ffe6.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 April 2019 15:28 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/6 "2019-04-18T15:28:12Z")

</div>

the error says you can't trim "undefined" so whay is what you are tyring to trim undefined? Look at your code and ask yourself why is it undefined.

In cases like this, I add node.warns to show me variables I am using in the debug. Try  
`node.warn("input="+input);`  
right after you define it and see want it is.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 April 2019 15:39 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/7 "2019-04-18T15:39:52Z")

</div>

wait. did you change the function node as I said ?

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [18 April 2019 15:42 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/8 "2019-04-18T15:42:08Z")

</div>

Yes I did  
!

 ![33%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/25d0757b4cf300e122b5d6beac099543fde5587e.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 April 2019 15:46 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/9 "2019-04-18T15:46:58Z")

</div>

can you post the full output of the 1st debug node ? and change the debug node to 'complete msg object' (not msg.payload)

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [18 April 2019 16:10 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/10 "2019-04-18T16:10:14Z")

</div>

I'm not sure if this is correct, it looks the same. Is this the setting to change?

 ![32%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/28db4fbb35a5fff9794d4affeae8a58b48f655f5.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 April 2019 16:13 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/11 "2019-04-18T16:13:05Z")

</div>

Ok if there is no difference that is fine.  
Could you post the full output (in text) ?

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [18 April 2019 16:13 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/12 "2019-04-18T16:13:41Z")

</div>

TypeError: Cannot read property 'trim' of undefined

```auto
TypeError: Cannot read property 'trim' of undefined

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 April 2019 16:14 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/13 "2019-04-18T16:14:26Z")

</div>

The one that is attached to the python script

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [18 April 2019 16:19 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/14 "2019-04-18T16:19:17Z")

</div>

I just noticed sometimes there are two messages

```auto
config register byte: 90RTD ADC Code: 8227

```

```auto
PT100 Resistance: 107.959290 ohmsStraight Line Approx. Temp: 1.093750 degCCallendar-Van Dusen Temp (degC > 0): 20.426748 degChigh fault threshold: 32767low fault threshold: 0

```

OR a single message like the one below

```auto
config register byte: 90RTD ADC Code: 8228PT100 Resistance: 107.972412 ohmsStraight Line Approx. Temp: 1.125000 degCCallendar-Van Dusen Temp (degC > 0): 20.460528 degChigh fault threshold: 32767low fault threshold: 0

```

 ![42%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cebf763536cb323a9b232f1d5bc0908e3a4faa2e.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 April 2019 16:51 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/16 "2019-04-18T16:51:19Z")

</div>

Your output has an enter after the last item causing the loop to fail.

Change:

`for(x=0;x<row.length;x++){`  
to  
`for(x=0;x<row.length-1;x++){`

---

<div class="post-metadata">

**Author:** ![dustinw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dustinw/32/3426_2.png) [@dustinw](https://discourse.nodered.org/u/dustinw)\
**Post date:** [18 April 2019 18:56 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/17 "2019-04-18T18:56:16Z")

</div>

One possible hint for the future: Bakman2's example does a perfect job of splitting up the message into an object, but you may want to simplify the keys ... e.g.

This will strip spaces and special characters from the keys:

```auto
key = input[0].replace(/[^a-zA-Z0-9]/g, '').trim().split(' ').join('_');
output[key] = parseFloat(input[1].trim());  

```

After that code change the payload in the message looks like:

```auto
{
  "RTD_ADC_Code":7627,
  "PT100_Resistance":100.085754,
  "Straight_Line_Approx_Temp":-17.65625,
  "CallendarVan_Dusen_Temp_degC__0":0.219423,
  "high_fault_threshold":32767,
  "low_fault_threshold":0
}

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [18 April 2019 20:45 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/18 "2019-04-18T20:45:22Z")

</div>

you're right, i've should have fixed that.

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [18 April 2019 23:02 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/19 "2019-04-18T23:02:24Z")

</div>

Where should I place the code, should I use the above modification and then use your code? I've tried several different ways and it didn't work, and I'm certain its me. I am very new to this. I've attached a screen shot of bakman2's code. Which lines do I replace?

 ![34%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/75a054e9f9c23f89e39f97847c494669c40c0daa.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 April 2019 06:10 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/20 "2019-04-19T06:10:59Z")

</div>

My Pi just crashed so i have to rebuild everything.

Under `input = row[...` you put:

`key = input[0].replace(/[^a-zA-Z0-9]/g, '').trim().split(' ').join('_');`

and replace:  
`output[input[0]]....` with:  
`output[key] = parseFloat(input[1].trim());`

and change `row.length` into `row.length-1`

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [19 April 2019 15:19 UTC](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318/21 "2019-04-19T15:19:13Z")

</div>

That worked. Thank you ! but...

I've used this command before in another flow to remove the extra items that I don't need-

```auto
msg.payload = msg.humidity 
return msg;

```

that strips the number from a multi part message.

I think the parts of this message are different than the above example, with the above, number values are in quotes and red text. I tried this with no luck-

```auto
msg.payload = msg.CallendarVan_Dusen_Temp_degC__0
return msg;

```

It doesn't work. I get this-

 ![20%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a1d8a3f545bfb50cdaf778e5498747be989b3b03.png)

How can I get this one number as an output?

Also, how do I find out what the different types of information in the debug output are called? IE What does it mean if the text is purple or red or blue. I'm happy to read up on this myself, I'm not sure what to google to find the answer

[Next page](https://discourse.nodered.org/t/separating-object-payload-help-solved-thank-you-all/10318.md?page=2)
