# Parse data from Webhook

**URL:** <https://community.n8n.io/t/parse-data-from-webhook/8571>\
**Category:** Questions\
**Tags:** data-transformation\
**Created:** [October 19, 2021, 5:41pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571 "2021-10-19T17:41:50Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![streczz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/streczz/32/7507_2.png) [@streczz](https://community.n8n.io/u/streczz)\
**Post date:** [October 19, 2021, 5:41pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/1 "2021-10-19T17:41:50Z")

</div>

Hello,

I’m new to n8n. I’m trying to extract certain data from webhook but I’m can’t get the field value I want.

The data I’m receiving from webhook has this format:

```auto
 "body": {
"Doc": "[{'name': 'f90c69a98d', 'owner': 'Administrator', 'creation': '2021-10-19 19:18:58.145465',}, {'name': 'b43e7bd05a', 'owner': 'Administrator', 'creation': '2021-10-19 19:18:58.145465',}]"

```

I need to extract the name field value. In the request I can find many names.

Can anybody point me in the right direction?

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [October 19, 2021, 6:07pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/2 "2021-10-19T18:07:53Z")

</div>

Welcome to the community @streczz

That is probably because the property is `Doc` is a string, not a JSON. So you have to parse the property `Doc` to a JSON and then use dot notation to get the values. A function node should do it.

```auto
const docs = JSON.parse(items[0].json.body.Doc.replace(/\'/g, '"'))

const results = []

for (const doc of docs) {
results.push({
    json: {
        name: doc.name
   }
})
}

return results

```

> **Example workflow**
>

---

<div class="post-metadata">

**Author:** ![streczz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/streczz/32/7507_2.png) [@streczz](https://community.n8n.io/u/streczz)\
**Post date:** [October 19, 2021, 6:47pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/3 "2021-10-19T18:47:10Z")

</div>

> [@RicardoE105](#):
>

Thank you for your reply. Unfortunately I’m getting this:

```auto
TypeError: Cannot read property 'replace' of undefined

```

---

<div class="post-metadata">

**Author:** ![streczz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/streczz/32/7507_2.png) [@streczz](https://community.n8n.io/u/streczz)\
**Post date:** [October 19, 2021, 6:51pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/4 "2021-10-19T18:51:13Z")

</div>

Sorry this was a typo mistake.

I’m getting this error:

```auto
SyntaxError: Unexpected token d in JSON at position 289

```

This is the full request

```auto
[
{
"headers": {
"host": "xxx",
"user-agent": "python-requests/2.25.1",
"accept-encoding": "gzip, deflate",
"accept": "*/*",
"connection": "keep-alive",
"content-type": "application/json",
"content-length": "1235"
},
"params": {
},
"query": {
},
"body": {
"Doc": "[{'name': '31f3bfe7cf', 'owner': 'Administrator', 'creation': '2021-10-19 19:18:58.145465', 'modified': '2021-10-19 20:50:10.529949'}, {'name': '70690477d3', 'owner': 'Administrator', 'creation': '2021-10-19 19:18:58.145465', 'modified': '2021-10-19 20:50:10.529949'}]"
}
}
]

```

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [October 19, 2021, 6:55pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/5 "2021-10-19T18:55:46Z")

</div>

Try it like this:

```auto
const docs = JSON.parse(items[0].json.body.Doc.replace(/\'/g, '"').replace(/\, }/g, '}'))

const results = []

for (const doc of docs) {
results.push({
    json: {
        name: doc.name
   }
})
}

return results

```

---

<div class="post-metadata">

**Author:** ![streczz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/streczz/32/7507_2.png) [@streczz](https://community.n8n.io/u/streczz)\
**Post date:** [October 19, 2021, 6:57pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/6 "2021-10-19T18:57:16Z")

</div>

> [@RicardoE105](#):
>
> ```auto
> const docs = JSON.parse(items[0].json.body.Doc.replace(/\'/g, '"').replace(/\, }/g, '}'))
> 
> const results = []
> 
> for (const doc of docs) {
> results.push({
> json: {
> name: doc.name
> }
> })
> }
> 
> return results
> 
> ```

Thank you but I’m getting the same error:

```auto
SyntaxError: Unexpected token n in JSON at position 267

```

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [October 19, 2021, 6:59pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/7 "2021-10-19T18:59:24Z")

</div>

Can you provide a sample of the data you are working with? Because for me it works fine.

---

<div class="post-metadata">

**Author:** ![streczz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/streczz/32/7507_2.png) [@streczz](https://community.n8n.io/u/streczz)\
**Post date:** [October 19, 2021, 7:00pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/8 "2021-10-19T19:00:54Z")

</div>

Yes, this is my test workflow

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [October 19, 2021, 7:08pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/9 "2021-10-19T19:08:13Z")

</div>

It does not work because that input is different than the one you showed initially. Given that input, the function below should do it, but if you change the input again, it will stop working.

```auto
const docs = JSON.parse(JSON.parse(items[0].json.body.Doc)[0].body.Doc.replace(/\'/g, '"').replace(/\, }/g, '}'))

const results = []

for (const doc of docs) {
results.push({
    json: {
        name: doc.name
   }
})
}

return results

```

---

<div class="post-metadata">

**Author:** ![streczz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/streczz/32/7507_2.png) [@streczz](https://community.n8n.io/u/streczz)\
**Post date:** [October 19, 2021, 7:16pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/10 "2021-10-19T19:16:56Z")

</div>

> [@RicardoE105](#):
>
> ```auto
> const docs = JSON.parse(JSON.parse(items[0].json.body.Doc)[0].body.Doc.replace(/\'/g, '"').replace(/\, }/g, '}'))
> 
> const results = []
> 
> for (const doc of docs) {
> results.push({
> json: {
> name: doc.name
> }
> })
> }
> 
> return results
> 
> ```

Thank you for your reply. The problem is the Webhook because the request is not always the same.

Now I’m getting this request :

```auto
"body": {
"Doc": "[{'name': '31f3bfe7cf', 'owner': 'Administrator', 'creation': '2021-10-19 19:18:58.145465', 'modified': '2021-10-19 21:12:05.300580', 'modified_by': 'Administrator', 'parent': 'T-2021-00028', 'parentfield': 'archivos_adjuntos', 'parenttype': 'Task', 'idx': 1, 'docstatus': 0, 'doc_fecha': datetime.date(2021, 10, 19), 'doc_titulo': 'Prueba Again', 'doc_adjunto': '/files/Unknown.jpeg', 'doctype': 'Documentos'}, {'name': '70690477d3', 'owner': 'Administrator', 'creation': '2021-10-19 19:18:58.145465', 'modified': '2021-10-19 21:12:05.300580', 'modified_by': 'Administrator', 'parent': 'T-2021-00028', 'parentfield': 'archivos_adjuntos', 'parenttype': 'Task', 'idx': 2, 'docstatus': 0, 'doc_fecha': datetime.date(2021, 10, 19), 'doc_titulo': 'Prueba 2', 'doc_adjunto': '/files/Unknown.jpeg', 'doctype': 'Documentos'}, {'name': 'e759e30ae0', 'owner': 'Administrator', 'creation': '2021-10-19 19:18:58.145465', 'modified': '2021-10-19 21:12:05.300580', 'modified_by': 'Administrator', 'parent': 'T-2021-00028', 'parentfield': 'archivos_adjuntos', 'parenttype': 'Task', 'idx': 3, 'docstatus': 0, 'doc_fecha': datetime.date(2021, 10, 19), 'doc_titulo': 'Prueba3', 'doc_adjunto': '/files/Unknown.jpeg', 'doctype': 'Documentos'}, {'name': '84370e091a', 'owner': 'Administrator', 'creation': '2021-10-19 19:18:58.145465', 'modified': '2021-10-19 21:12:05.300580', 'modified_by': 'Administrator', 'parent': 'T-2021-00028', 'parentfield': 'archivos_adjuntos', 'parenttype': 'Task', 'idx': 4, 'docstatus': 0, 'doc_fecha': datetime.date(2021, 10, 19), 'doc_titulo': 'Prueba4', 'doc_adjunto': '/files/Unknown.jpeg', 'doctype': 'Documentos'}, {'name': 'f8e8e32ac3', 'owner': 'Administrator', 'creation': '2021-10-19 19:18:58.145465', 'modified': '2021-10-19 21:12:05.300580', 'modified_by': 'Administrator', 'parent': 'T-2021-00028', 'parentfield': 'archivos_adjuntos', 'parenttype': 'Task', 'idx': 5, 'docstatus': 0, 'doc_fecha': datetime.date(2021, 10, 19), 'doc_titulo': 'Prueba5', 'doc_adjunto': '/files/Unknown.jpeg', 'doctype': 'Documentos'}]"
}

```

I need to understand your function in order to customize it.

With no changes, I’m getting this:

```auto
SyntaxError: Unexpected token ' in JSON at position 2

```

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [October 19, 2021, 7:18pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/11 "2021-10-19T19:18:48Z")

</div>

You need to standardize the way you receive data in the webhook node. Otherwise, it’s going to be extremely difficult to develop an algorithm that works with all possible input variations.

---

<div class="post-metadata">

**Author:** ![streczz](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/streczz/32/7507_2.png) [@streczz](https://community.n8n.io/u/streczz)\
**Post date:** [October 19, 2021, 7:20pm UTC](https://community.n8n.io/t/parse-data-from-webhook/8571/12 "2021-10-19T19:20:40Z")

</div>

Yes.

I think I can standardize. I will try to customize your function.

Thank you very much for your help, much appreciated.
