# Passing only certain values from a payload?

**URL:** https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356
**Category:** Developing Nodes
**Created:** [16 October 2020 16:06 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356 "2020-10-16T16:06:39Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![MinesCaves](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minescaves/32/11248_2.png) [@MinesCaves](https://discourse.nodered.org/u/MinesCaves)
#### Post date: [16 October 2020 16:06 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/1 "2020-10-16T16:06:39Z")

</div>

Alright guys, I feel like a knucklehead. Node-red has been running beautifully for awhile and I haven't needed to change anything. Now I need to extrapolate some data from an object and only pass those values. I thought I did it before with a Function Node, but I can't seem to get anything to work. This is the incoming data.

```auto
{"data":{"common":{"productId":{"wwwItemId":"276","upca":"630","productId":"7A9H","offerId":"EE212DDAE","ean13":"060312"},"name":"Litvst","department":"","thumbnailImageUrl":"","productImageUrl":"https://","customerRating":{"rating":4.1,"count":152},"productUrl":"https://","variantSwatches":[],"offerType":"ONLINE_AND_STORE","twoDayShippingEligible":false,"storePickupAvailable":false,"storePickupAvailableToday":false,"nextDayShippingEligible":false},"inStore":{"price":{"priceInCents":1000,"currencyUnit":"USD"},"location":{"aisles":["N9"],"detailedAisles":[{"zoneName":"N","aisleName":9,"sectionName":2}]},"storeId":XXXX},"online":{"price":{"priceInCents":2499,"currencyUnit":"USD","showInCart":false},"inventory":{"status":"In Stock","available":true},"specialOfferBadge":"rollback","specialOfferText":"Rollback"},"relatedItemsUrls":{"inStore":"https://","online":"https"}}

```

The values from the msg.payload is msg.payload.data.common.name, msg.payload.data.inStore.price.priceInCents, payload.data.inStore.storeId, etc.

I have a change node and function node which will extract msg.payload.data.common.name, but it becomes it's own separate message. I'd basically like to remove all the useless info from the payload. I just can't remember how.

```auto
[{"id":"822d599.c1c9ca8","type":"change","z":"c3e84d4e.4ead68","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.data.common.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":2160,"wires":[["1cb49f4.fe872e1","d847038d.95dde"]]},{"id":"1cb49f4.fe872e1","type":"function","z":"c3e84d4e.4ead68","name":"","func":"msg.payload = `Name:${msg.payload}`;\nreturn msg;","outputs":1,"noerr":0,"x":1130,"y":2160,"wires":[["3a4f0c57.7d8c74","a26ef6e1.a115d8"]]}]

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 October 2020 16:36 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/2 "2020-10-16T16:36:38Z")

</div>

There are many ways to skin a cat  
e.g.

```auto
[{"id":"febf56d.68015a8","type":"inject","z":"6fcc3140.459a2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"common\":{\"productId\":{\"wwwItemId\":\"276\",\"upca\":\"630\",\"productId\":\"7A9H\",\"offerId\":\"EE212DDAE\",\"ean13\":\"060312\"},\"name\":\"Litvst\",\"department\":\"\",\"thumbnailImageUrl\":\"\",\"productImageUrl\":\"https://\",\"customerRating\":{\"rating\":4.1,\"count\":152},\"productUrl\":\"https://\",\"variantSwatches\":[],\"offerType\":\"ONLINE_AND_STORE\",\"twoDayShippingEligible\":false,\"storePickupAvailable\":false,\"storePickupAvailableToday\":false,\"nextDayShippingEligible\":false},\"inStore\":{\"price\":{\"priceInCents\":1000,\"currencyUnit\":\"USD\"},\"location\":{\"aisles\":[\"N9\"],\"detailedAisles\":[{\"zoneName\":\"N\",\"aisleName\":9,\"sectionName\":2}]},\"storeId\":1111},\"online\":{\"price\":{\"priceInCents\":2499,\"currencyUnit\":\"USD\",\"showInCart\":false},\"inventory\":{\"status\":\"In Stock\",\"available\":true},\"specialOfferBadge\":\"rollback\",\"specialOfferText\":\"Rollback\"},\"relatedItemsUrls\":{\"inStore\":\"https://\",\"online\":\"https\"}}}","payloadType":"json","x":220,"y":840,"wires":[["394060bf.ee1b3","97de1444.6039"]]},{"id":"394060bf.ee1b3","type":"change","z":"6fcc3140.459a2","name":"","rules":[{"t":"set","p":"hold","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.common.name","pt":"msg","to":"hold.data.common.name","tot":"msg"},{"t":"set","p":"payload.data.inStore.price.priceInCents","pt":"msg","to":"hold.data.inStore.price.priceInCents","tot":"msg"},{"t":"set","p":"payload.data.inStore.storeId","pt":"msg","to":"hold.data.inStore.storeId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":860,"wires":[["c7c1897c.129798"]]},{"id":"97de1444.6039","type":"debug","z":"6fcc3140.459a2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":660,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![MinesCaves](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minescaves/32/11248_2.png) [@MinesCaves](https://discourse.nodered.org/u/MinesCaves)
#### Post date: [16 October 2020 16:46 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/3 "2020-10-16T16:46:56Z")

</div>

> [@E1cid](#):
>
> `[{"id":"febf56d.68015a8","type":"inject","z":"6fcc3140.459a2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"common\":{\"productId\":{\"wwwItemId\":\"276\",\"upca\":\"630\",\"productId\":\"7A9H\",\"offerId\":\"EE212DDAE\",\"ean13\":\"060312\"},\"name\":\"Litvst\",\"department\":\"\",\"thumbnailImageUrl\":\"\",\"productImageUrl\":\"https://\",\"customerRating\":{\"rating\":4.1,\"count\":152},\"productUrl\":\"https://\",\"variantSwatches\":[],\"offerType\":\"ONLINE_AND_STORE\",\"twoDayShippingEligible\":false,\"storePickupAvailable\":false,\"storePickupAvailableToday\":false,\"nextDayShippingEligible\":false},\"inStore\":{\"price\":{\"priceInCents\":1000,\"currencyUnit\":\"USD\"},\"location\":{\"aisles\":[\"N9\"],\"detailedAisles\":[{\"zoneName\":\"N\",\"aisleName\":9,\"sectionName\":2}]},\"storeId\":1111},\"online\":{\"price\":{\"priceInCents\":2499,\"currencyUnit\":\"USD\",\"showInCart\":false},\"inventory\":{\"status\":\"In Stock\",\"available\":true},\"specialOfferBadge\":\"rollback\",\"specialOfferText\":\"Rollback\"},\"relatedItemsUrls\":{\"inStore\":\"https://\",\"online\":\"https\"}}}","payloadType":"json","x":220,"y":840,"wires":[["394060bf.ee1b3","97de1444.6039"]]},{"id":"394060bf.ee1b3","type":"change","z":"6fcc3140.459a2","name":"","rules":[{"t":"set","p":"hold","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.common.name","pt":"msg","to":"hold.data.common.name","tot":"msg"},{"t":"set","p":"payload.data.inStore.price.priceInCents","pt":"msg","to":"hold.data.inStore.price.priceInCents","tot":"msg"},{"t":"set","p":"payload.data.inStore.storeId","pt":"msg","to":"hold.data.inStore.storeId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":860,"wires":[["c7c1897c.129798"]]},{"id":"97de1444.6039","type":"debug","z":"6fcc3140.459a2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":660,"wires":[]}]`

This certainly works! But I fail to understand why.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 October 2020 16:52 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/4 "2020-10-16T16:52:30Z")

</div>

first it copies payload to hold  
then it clears payload.  
then it moves items from hold back to payload.

---

<div class="post-metadata">

### Author: ![MinesCaves](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minescaves/32/11248_2.png) [@MinesCaves](https://discourse.nodered.org/u/MinesCaves)
#### Post date: [16 October 2020 17:50 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/5 "2020-10-16T17:50:29Z")

</div>

That's awesome! I had no idea you could do that.

Is there a way to make it spit out

name : TheNameOfSomething  
price : priceInCents1000  
storeId : XXX

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 October 2020 17:53 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/6 "2020-10-16T17:53:13Z")

</div>

That's Node-red's excellent low code interface. Respect Dev's

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 October 2020 18:03 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/7 "2020-10-16T18:03:08Z")

</div>

i would think so.  
where are

```auto
name : TheNameOfSomething
price : priceInCents1000
storeId : XXX

```

located in your object?

And is that the string format or an object?

---

<div class="post-metadata">

### Author: ![MinesCaves](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minescaves/32/11248_2.png) [@MinesCaves](https://discourse.nodered.org/u/MinesCaves)
#### Post date: [16 October 2020 18:21 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/8 "2020-10-16T18:21:43Z")

</div>

So if I use your example, I get

```auto
payload.data.common.name
payload.data.inStore.price.priceInCents
payload.data.inStore.storeId

```

in the debug node. I'm just curious if there's a way to make it look more clean (it'll be going into a spreadsheet hopefully.)

```auto
{{name : payload.data.common.name, price : payload.data.inStore.price.priceInCents, store : payload.data.inStore.storeId}}

```

(I have no idea what I'm doing. I can't remember how it worked.)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 October 2020 18:41 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/9 "2020-10-16T18:41:11Z")

</div>

try

```auto
[{"id":"75500b3f.812ff4","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"hold","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.name","pt":"msg","to":"hold.data.common.name","tot":"msg"},{"t":"set","p":"payload.price","pt":"msg","to":"{'priceInCents': hold.data.inStore.price.priceInCents} ","tot":"jsonata"},{"t":"set","p":"payload.storeId","pt":"msg","to":"hold.data.inStore.storeId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":780,"wires":[["ca18810d.3ed83"]]}]

```

---

<div class="post-metadata">

### Author: ![MinesCaves](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minescaves/32/11248_2.png) [@MinesCaves](https://discourse.nodered.org/u/MinesCaves)
#### Post date: [16 October 2020 19:18 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/10 "2020-10-16T19:18:23Z")

</div>

So close! The `{'priceInCents': hold.data.inStore.price.priceInCents}` comes up as it's own object and then you have to drill down to get the price.

In the debug node it shows `{"name":"Litvst","price":OBJECT,"storeId":1111}`

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 October 2020 19:24 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/11 "2020-10-16T19:24:22Z")

</div>

> [@E1cid](#):
>
> ```auto
> name : TheNameOfSomething
> price : priceInCents1000
> storeId : XXX
> 
> ```

I did ask about your format, but you never answered. so from above i took the different colour of the 1000 as it was an object. How exactly do you wish the value in price to look?

---

<div class="post-metadata">

### Author: ![MinesCaves](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minescaves/32/11248_2.png) [@MinesCaves](https://discourse.nodered.org/u/MinesCaves)
#### Post date: [16 October 2020 19:31 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/12 "2020-10-16T19:31:57Z")

</div>

Oh sorry about that, I must have missed it. I'm curling json data from a website. The 1000 is a variable that changes based on what I'm curling. So, I'm really not sure what it is. Thank you for your help. I'm terrible with node-red (javascript, variables, programming, function nodes, etc etc etc)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 October 2020 19:43 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/13 "2020-10-16T19:43:22Z")

</div>

> [@E1cid](#):
>
> How exactly do you wish the value in price to look?

You never answer the question, I want the exact format you require. In future when asking for help it is best to give clear examples of input (your original json has an error , created by you when you edited in XXXX. a string with out quotes), and output, with clear examples, so people only have to do thing once. This is the third attempt, lets get it right this time.

---

<div class="post-metadata">

### Author: ![MinesCaves](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minescaves/32/11248_2.png) [@MinesCaves](https://discourse.nodered.org/u/MinesCaves)
#### Post date: [16 October 2020 19:59 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/14 "2020-10-16T19:59:05Z")

</div>

I guess I'm trying to take

```auto
{"data":{"common":{"productId":{"wwwItemId":"276","upca":"630","productId":"7A9H","offerId":"EE212DDAE","ean13":"060312"},"name":"Litvst","department":"","thumbnailImageUrl":"","productImageUrl":"https://","customerRating":{"rating":4.1,"count":152},"productUrl":"https://","variantSwatches":[],"offerType":"ONLINE_AND_STORE","twoDayShippingEligible":false,"storePickupAvailable":false,"storePickupAvailableToday":false,"nextDayShippingEligible":false},"inStore":{"price":{"priceInCents":1099,"currencyUnit":"USD"},"location":{"aisles":["N9"],"detailedAisles":[{"zoneName":"N","aisleName":9,"sectionName":2}]},"storeId":2231},"online":{"price":{"priceInCents":2499,"currencyUnit":"USD","showInCart":false},"inventory":{"status":"In Stock","available":true},"specialOfferBadge":"rollback","specialOfferText":"Rollback"},"relatedItemsUrls":{"inStore":"https://","online":"https"}}

```

and have it display

"name":"Litvst"  
"priceInCents":1099  
"storeId":2231

Thats from the JSON I pulled. Those are the only values I need to extract from that long JSON. If it's an object, or string, or buffer, I really have no idea. All I know is the "Name" "priceInCents" and "storeId" values change depending what is being pulled.

I could curl another JSON and it coulf turn into

"name":"Tacos"  
"priceInCents":100  
"storeId":2771

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 October 2020 20:03 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/15 "2020-10-16T20:03:49Z")

</div>

ok let's hope.

```auto
[{"id":"75500b3f.812ff4","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"hold","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"msg"},{"t":"set","p":"payload.name","pt":"msg","to":"hold.data.common.name","tot":"msg"},{"t":"set","p":"payload.priceInCents","pt":"msg","to":"hold.data.inStore.price.priceInCents","tot":"msg"},{"t":"set","p":"payload.storeId","pt":"msg","to":"hold.data.inStore.storeId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":780,"wires":[["ca18810d.3ed83"]]}]

```

---

<div class="post-metadata">

### Author: ![MinesCaves](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minescaves/32/11248_2.png) [@MinesCaves](https://discourse.nodered.org/u/MinesCaves)
#### Post date: [16 October 2020 20:05 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/16 "2020-10-16T20:05:13Z")

</div>

> [@E1cid](#):
>
> `[{"id":"75500b3f.812ff4","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"hold","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"hold.data.inStore.price.priceInCents ","tot":"msg"},{"t":"set","p":"payload.name","pt":"msg","to":"hold.data.common.name","tot":"msg"},{"t":"set","p":"payload.priceInCents","pt":"msg","to":"hold.data.inStore.price.priceInCents","tot":"msg"},{"t":"set","p":"payload.storeId","pt":"msg","to":"hold.data.inStore.storeId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":780,"wires":[["ca18810d.3ed83"]]}]`

WOOHOO!! It worked!! Thank you so much!

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 October 2020 20:07 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/17 "2020-10-16T20:07:13Z")

</div>

just edited it to remove data property take another look at above post

---

<div class="post-metadata">

### Author: ![MinesCaves](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/minescaves/32/11248_2.png) [@MinesCaves](https://discourse.nodered.org/u/MinesCaves)
#### Post date: [16 October 2020 20:16 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/18 "2020-10-16T20:16:26Z")

</div>

Perfect!!!!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [30 October 2020 20:16 UTC](https://discourse.nodered.org/t/passing-only-certain-values-from-a-payload/34356/19 "2020-10-30T20:16:34Z")

</div>

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