# Extract dynamic json object to payload

**URL:** <https://discourse.nodered.org/t/extract-dynamic-json-object-to-payload/22205>\
**Category:** General\
**Created:** [24 February 2020 15:57 UTC](https://discourse.nodered.org/t/extract-dynamic-json-object-to-payload/22205 "2020-02-24T15:57:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcp](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@jcp](https://discourse.nodered.org/u/jcp)\
**Post date:** [24 February 2020 15:57 UTC](https://discourse.nodered.org/t/extract-dynamic-json-object-to-payload/22205/1 "2020-02-24T15:57:25Z")

</div>

Hi,  
I am new to node-red and also to javascript.  
I intend to extract a dynamic key/values from the data\_label object and put it in msg.payload just like the picture attached.  
How can I achieve this with the function node?  
Regards  
 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/94f7b6654192ad06dcdedeeffa1d73ebb6a1969e.png)

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [24 February 2020 16:09 UTC](https://discourse.nodered.org/t/extract-dynamic-json-object-to-payload/22205/2 "2020-02-24T16:09:11Z")

</div>

is this specific to `data_label`? If so, you can utilise a change node with JSONata:  
`$sift($merge([$$.payload, $$.payload.data_label]), function($val, $key) {$key != "data_label"})`

[https://try.jsonata.org/IOXYLdsO](https://try.jsonata.org/IOXYLdsO)

What this does is that it will merge `msg.payload` object with the inner `msg.payload.data_label` object, which will give you a combined object of

```javascript
{
  "@timestamp": "2020-02-24T...",
  "data_label": {
    "DATA0": 6573,
    "DATA1": 65
  },
  "DATA0": 6573,
  "DATA1": 65
}

```

Then, it will call a `$sift` function on it to filter out the key in the object called `data_label` to get the item out. Anyone having a more simplistic solution, feel free to show how to do it better, I love improved queries 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 February 2020 16:15 UTC](https://discourse.nodered.org/t/extract-dynamic-json-object-to-payload/22205/3 "2020-02-24T16:15:17Z")

</div>

Also have a look at the node red docs on Working With Messages, that will give you further help.

---

<div class="post-metadata">

**Author:** ![jcp](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@jcp](https://discourse.nodered.org/u/jcp)\
**Post date:** [24 February 2020 16:18 UTC](https://discourse.nodered.org/t/extract-dynamic-json-object-to-payload/22205/4 "2020-02-24T16:18:44Z")

</div>

Exactly what I needed!  
Thank you my friend.  
Regards

---

<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:** [9 March 2020 16:18 UTC](https://discourse.nodered.org/t/extract-dynamic-json-object-to-payload/22205/5 "2020-03-09T16:18:57Z")

</div>

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