# Getting key from the expression for custom node

**URL:** <https://community.n8n.io/t/getting-key-from-the-expression-for-custom-node/31955>\
**Category:** Questions\
**Tags:** node, custom-node\
**Created:** [Octobre 23, 2023, 10:00 UTC](https://community.n8n.io/t/getting-key-from-the-expression-for-custom-node/31955 "2023-10-23T22:00:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshil1712](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/harshil1712/32/1374_2.png) [@harshil1712](https://community.n8n.io/u/harshil1712)\
**Post date:** [Octobre 23, 2023, 10:00 UTC](https://community.n8n.io/t/getting-key-from-the-expression-for-custom-node/31955/1 "2023-10-23T22:00:31Z")

</div>

## Describe the problem/error/question

I am building a custom node. To make the automation seamless, I want to pass a part of the payload that I receive from my previous node. However, when using the expression in the input field, it resolves the expression. As a result, always the value is returned.

Eg.  
Payload from previous node:

```json
{
...,
displayName: 'Name'
}

```

When I use the expression, `{{ $json.displayName }}` in the input field of my custom node, it returns `Name`. What I would like to have is something like `{displayName: Name}`. What would be the best way to implement that in my custom node?

---

<div class="post-metadata">

**Author:** ![EmeraldHerald](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/emeraldherald/32/35355_2.png) [@EmeraldHerald](https://community.n8n.io/u/EmeraldHerald)\
**Post date:** [Octobre 24, 2023, 3:36 UTC](https://community.n8n.io/t/getting-key-from-the-expression-for-custom-node/31955/4 "2023-10-24T15:36:30Z")

</div>

Hi @harshil1712 👋 Maybe @marcus or @Jon could help you out? 😃

---

<div class="post-metadata">

**Author:** ![marcus](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/marcus/32/15989_2.png) [@marcus](https://community.n8n.io/u/marcus)\
**Post date:** [Octobre 25, 2023, 12:28 UTC](https://community.n8n.io/t/getting-key-from-the-expression-for-custom-node/31955/5 "2023-10-25T12:28:14Z")

</div>

Hey @harshil1712,  
expressions like `{{ $json.displayName }}` will only resolve the value but they won’t give you the key name. To set the key name you would need an additional string parameter. You could put both key/value parameters inside of a fixedCollection, like for example our Edit Fields (Set) node is doing [here](https://github.com/n8n-io/n8n/blob/6f45298d3d61b33e762f520129f4775e216707c8/packages/nodes-base/nodes/Set/v2/manual.mode.ts#L44). The `requiresDataPath: 'single'` property tells n8n to insert the key name (instead of an expression) when using drag/drop to map input fields.

---

<div class="post-metadata">

**Author:** ![harshil1712](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/harshil1712/32/1374_2.png) [@harshil1712](https://community.n8n.io/u/harshil1712)\
**Post date:** [Octobre 25, 2023, 10:15 UTC](https://community.n8n.io/t/getting-key-from-the-expression-for-custom-node/31955/6 "2023-10-25T22:15:42Z")

</div>

Thanks @marcus. This helped. I am interested in getting the last key in the chain, eg: if the expression looks like `{{ $json.body.displayName }}`, I would like to get `displayName`. `requiresDataPath` gives the whole path.

For now, I am handling this programatically, but is there an option that already takes care of this?

Also, out of curiosity, what is the difference between `requiresDataPath: 'single'` and `requiresDataPath: 'multiple'`?

---

<div class="post-metadata">

**Author:** ![marcus](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/marcus/32/15989_2.png) [@marcus](https://community.n8n.io/u/marcus)\
**Post date:** [Octobre 26, 2023, 1:05 UTC](https://community.n8n.io/t/getting-key-from-the-expression-for-custom-node/31955/7 "2023-10-26T13:05:16Z")

</div>

Hi @harshil1712,

> [@harshil1712](#):
>
> For now, I am handling this programatically, but is there an option that already takes care of this?

No there is no option to handle this automatically since most of the time we are interested in the full path.

> [@harshil1712](#):
>
> Also, out of curiosity, what is the difference between `requiresDataPath: 'single'` and `requiresDataPath: 'multiple'`?

When drag/drop multiple fields in the same node parameter n8n will either replace any existing value (single) or concatinate (multiple) ones comma separated.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [Janvier 24, 2024, 1:06 UTC](https://community.n8n.io/t/getting-key-from-the-expression-for-custom-node/31955/8 "2024-01-24T13:06:02Z")

</div>

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