# Extracting code

**URL:** <https://community.n8n.io/t/extracting-code/26382>\
**Category:** Questions\
**Created:** [May 20, 2023, 6:36pm UTC](https://community.n8n.io/t/extracting-code/26382 "2023-05-20T18:36:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JabmoBabo](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jabmobabo/32/25571_2.png) [@JabmoBabo](https://community.n8n.io/u/JabmoBabo)\
**Post date:** [May 20, 2023, 6:36pm UTC](https://community.n8n.io/t/extracting-code/26382/1 "2023-05-20T18:36:42Z")

</div>

How i can extract this part “test message here” from my API request?:

```json

[
{
"data":
"[{"envelope":{"source":"+4398575490","sourceNumber":"+4398575490","sourceUuid":"22afj3oi4nmfo-8e94-3fa0-a7e4-af6d3cef34c4","sourceName":"Gates","sourceDevice":2,"timestamp":1684596688622,"syncMessage":{"sentMessage":{"destination":null,"destinationNumber":null,"destinationUuid":null,"timestamp":1684596688622,"message":"test message here","expiresInSeconds":0,"viewOnce":false,"groupInfo":{"groupId":"l/EgH4qfkdjn349834f93ff25tiYygqzwjkAgfm349f309lE=","type":"DELIVER"}}}},"account":"+4398575490"}]"
}
]

```

I already try: `$[0].data[0].envelope.syncMessage.sentMessage.message`  
and  
`$.data[0].envelope.syncMessage.sentMessage.message` and nothing works.

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [May 20, 2023, 6:38pm UTC](https://community.n8n.io/t/extracting-code/26382/2 "2023-05-20T18:38:53Z")

</div>

Hey @JabmoBabo,

Welcome to the community 🙌

I would maybe use a set node and set the value to `{{ JSON.parse( $json.data ) }}` then in the next node you have a better object to work from.

---

<div class="post-metadata">

**Author:** ![JabmoBabo](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jabmobabo/32/25571_2.png) [@JabmoBabo](https://community.n8n.io/u/JabmoBabo)\
**Post date:** [May 20, 2023, 6:45pm UTC](https://community.n8n.io/t/extracting-code/26382/3 "2023-05-20T18:45:39Z")

</div>

It not works:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/5/d/5d20a2259c427de433a929ca9512e07c5b09c444.png)

But I fix it (gpt fix it) by using Code node and this code:

```auto
const message = JSON.parse($node["IF1"].json["data"])[0].envelope.syncMessage.sentMessage.message;
const messageWithoutPrefix = message.replace('/gpt ', '');
return [{ 'messageWithoutPrefix': messageWithoutPrefix }];

```

IF1 is a previous node.

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [May 20, 2023, 6:48pm UTC](https://community.n8n.io/t/extracting-code/26382/4 "2023-05-20T18:48:49Z")

</div>

Forgot to mention you would need to toggle the expression option. But glad you have sorted it 🙂

---

<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:** [May 27, 2023, 6:49pm UTC](https://community.n8n.io/t/extracting-code/26382/5 "2023-05-27T18:49:18Z")

</div>

Closed on May 27, 2023, 6:49pm UTC

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