Need Help for the Function Node to parse a JSON from a Webhook

Hi there :slight_smile:

First post here, i hope i did not miss the presentation topic :slight_smile:

Iโ€™m facing an issue with the combination between a webhook and the function node to parse the result from the webhook

Iโ€™m a marketer with some coding skill, but in Python :smiley:

The webhook comme from Albacross and look like this :

  "timestamp": 1560853854297,
  "name": "Lead Name",
  "country": "GB",
  "duration": 16548,
  "address": {
"address": "Street 123" | null,
"city": "London" | null,
"zip_code": "12345" | null,
"state": 'London' | null
  "contacts_url": "",
  "employees": {
"from": 10 | null,
"to": 50 | null,
"year": 2019 | null
  "financial_report": {
revenue_from: 10000001 | null,
revenue_to: 50000000 | null,
"currency": "EUR" | null,
"year": 2019 | null
  "founded_at": 2013 | null,
  "gclids": ["CjwKCAjw"],
  "industry_category": "COMPUTER HARDWARE" | null,
  "industry_code": "3" | null,
  "last_visit": 1571395887605,
  "nace_code": "6201" | null,
  "nace_text": "Computer programming activities" | null,
  "number": 'GB00000001',
  "pages_visited": 361,
  "visits": 121,
  "website": "" | null,
  "pages": [
  "key": "/lead/all",
  "value": 6,
  "value_percentage": 1.66
  "phone_number": {
"country": "GB" | null,
"country_code": 440 | null,
"number": "+44 123 456 789 | null"
  "profile_url": "",
  "utms": {
  "sources": ["invite"],
  "mediums": ["email"],
  "campaigns": ["report"],
  "terms": ["leads_page"],
  "contents": []
  "contacts": [
  "email": "[email protected]",
  "first_name": "John" | null,
  "last_name": "Doe" | null,
  "position": "senior" | null,
  "department": "it" | null,
  "phone_number": "+44 123 456 789" | null,
  "linkedin": "" | null

My function looklike this :

return JSON.parse(items[0]);

And I get an error. I also tried some function found here in the forum, without success.

Can someone help me ?

Hi @dubarseo,

What error message are you getting? I find it is best to execute the webhook and send your data then you can see how n8n will get it and can then step through nodes from there to get what you are after.

Hi @jon Thank for your help :slight_smile:

Iโ€™m having this error :

Welcome to the community @dubarseo !

You have two problems:

  1. items[0] contains an object and can so not be JSON.parsed. For that reason do you get that error. Honestly do not understand why you have to do that anyway. If the webhook receives JSON data it should already be parsed, so there should be no need. If you want to parse something then would be a specific key underneath it and that key would be underneath json (look at the n8n data structure. So you would have to do more something like JSON.parse(items[0].json.key)
  2. You do not return data in the right format. You have to return an array of objects with json property. Check also for that the link of the n8n data structure.

Here the documentation of the Function-Node:

Hope that helps!


Thank you @jan itโ€™s help a lot. My first mistake was to use production URL for my webhook. Reading your reply about the json already parsed made me realize that, i change for webhook test URL, since i can use the SET node, wich is exactly what i need :slight_smile: