# Creating payload objects in a function node

**URL:** <https://forums.losant.com/t/creating-payload-objects-in-a-function-node/4202>\
**Category:** Help\
**Tags:** workflow\
**Created:** [November 16, 2021, 11:07pm UTC](https://forums.losant.com/t/creating-payload-objects-in-a-function-node/4202 "2021-11-16T23:07:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [November 16, 2021, 11:07pm UTC](https://forums.losant.com/t/creating-payload-objects-in-a-function-node/4202/1 "2021-11-16T23:07:52Z")

</div>

Is there a good example of how I can dynamically create new payload objects within a function node?

for example:  
payload.data.value1 (is a numeric value: 10)  
payload.data.value2 (is a string : ‘abc’)

I would like a new payload object where the name is a combination of the 2.  
i.e : name is payload.data.abc and the value is 10

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [November 17, 2021, 12:07am UTC](https://forums.losant.com/t/creating-payload-objects-in-a-function-node/4202/2 "2021-11-17T00:07:33Z")

</div>

To confirm, your incoming payload is …

```json
{
  "payload": {
    "data": {
      "value1": 10,
      "value2": "abc"
    }
  }
}

```

… and your desired payload is …

```json
{
  "payload": {
    "data": {
      "value1": 10,
      "value2": "abc",
      "abc": 10 // key matches the value of value2, value matches the value of value1
    }
  }
}

```

This is a straightforward assignment operation in JavaScript using [bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#bracket_notation), which allows for reading and writing properties with either names that aren’t valid in [dot notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#dot_notation) or names referenced as variables …

```javascript
payload.data[payload.data.value2] = payload.data.value1;

```

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [November 17, 2021, 12:23pm UTC](https://forums.losant.com/t/creating-payload-objects-in-a-function-node/4202/3 "2021-11-17T12:23:21Z")

</div>

ok, thanks. Can this be used in a Mutate node as well?

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [November 17, 2021, 4:00pm UTC](https://forums.losant.com/t/creating-payload-objects-in-a-function-node/4202/4 "2021-11-17T16:00:21Z")

</div>

It’s actually _not_ possible to do in a Mutate Node, as we do not have any mechanism for dynamically setting a payload path for the destination of the new value.

But that question has come up before and I’ll +1 the feature request.
