Describe the problem/error/question
Hi,
I’m getting a json from an HTTP call and extracting some values from it to create a new json for a webhook response.
The webhook response is properly setup and works with some other code.
Right now I have a code module that takes the first json and transform it into an array. I tried to turn it in a json in various ways.
My closest solution (below) so far seems good… But a bracket is added at the end of the input item when I try to use it in the webhook response.
I feel stuck right now and can’t seem to figure it out. What am I doing wrong? Or is there a bug?
The ideal webhook response would look like:
[
{
"id": "0a61l",
"block": "form",
"inputs": [
{
"type": "select",
"name": "A select",
"label": "Owner",
"selectValues": [
{
"name": "My first value",
"value": "my-first-value"
},
{
"name": "My second value",
"value": "my-second-value"
},
{
"name": "07q6h96c0671vjq4",
"value": "07q6h96c0671vjq4"
},
{
"name": "tw5947pt1fop5t",
"value": "tw5947pt1fop5t"
},
{
"name": "vb5qtk37fmk31v1u",
"value": "vb5qtk37fmk31v1u"
},
{
"name": "eyuzd4nv34e17db2",
"value": "eyuzd4nv34e17db2"
},
{
"name": "osg53hexfy1w9n1",
"value": "osg53hexfy1w9n1"
},
{
"name": "poz1nrd1pe1a7b9",
"value": "poz1nrd1pe1a7b9"
},
{
"name": "8h21271ae2ed9",
"value": "8h21271ae2ed9"
},
{
"name": "mu1g5xfrormjllg",
"value": "mu1g5xfrormjllg"
},
{
"name": "y6hyevbo8j960y2l",
"value": "y6hyevbo8j960y2l"
},
{
"name": "v6xp3tatg419jom",
"value": "v6xp3tatg419jom"
},
{
"name": "yl7vowutfypcor",
"value": "yl7vowutfypcor"
}
]
}
],
"actionButton": {
"name": "My Button",
"label": "My Action Button",
"style": "secondary"
},
"url": "http://callback.url.com"
}
]
What is the error message (if any)?
“ERROR: Invalid JSON in ‘Response Body’ field
Check that the syntax of the JSON in the ‘Response Body’ parameter is valid”
(and that’s about right!)
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
Share the output returned by the last node
The json body is incorrect because I have one bracket too many here :
“value”: “yl7vowutfypcor”}}] (code below)
What’s weird is that the json from the last scenario seems fine when I look at it from the left side panel… But using {{ $json.inputs }} seems to add a } for some reason.
Here is the output of the last node before the webhook response:
[
{
"id": "elmjw149",
"block": "form",
"inputs": [
{
"type": "select",
"name": "A select",
"label": "Owner",
"selectValues": [
{
"name": "My first value",
"value": "my-first-value"
},
{
"name": "My second value",
"value": "my-second-value"
},
{
"name": "07q6h96c0671vjq4",
"value": "07q6h96c0671vjq4"
},
{
"name": "tw5947pt1fop5t",
"value": "tw5947pt1fop5t"
},
{
"name": "vb5qtk37fmk31v1u",
"value": "vb5qtk37fmk31v1u"
},
{
"name": "eyuzd4nv34e17db2",
"value": "eyuzd4nv34e17db2"
},
{
"name": "osg53hexfy1w9n1",
"value": "osg53hexfy1w9n1"
},
{
"name": "poz1nrd1pe1a7b9",
"value": "poz1nrd1pe1a7b9"
},
{
"name": "8h21271ae2ed9",
"value": "8h21271ae2ed9"
},
{
"name": "mu1g5xfrormjllg",
"value": "mu1g5xfrormjllg"
},
{
"name": "y6hyevbo8j960y2l",
"value": "y6hyevbo8j960y2l"
},
{
"name": "v6xp3tatg419jom",
"value": "v6xp3tatg419jom"
},
{
"name": "yl7vowutfypcor",
"value": "yl7vowutfypcor"
}
]
}
],
"actionButton": {
"name": "My Button",
"label": "My Action Button",
"style": "secondary"
},
"url": "http://callback.url.com"
}
]
And “output” (what I see in the Response Body module):
[
{
"id": "0a61l",
"block": "form",
"inputs": [{"type": "select", "name": "A select", "label": "Owner", "selectValues": [{"name": "My first value", "value": "my-first-value"},{"name": "My second value", "value": "my-second-value"},{"name": "07q6h96c0671vjq4", "value": "07q6h96c0671vjq4"},{"name": "tw5947pt1fop5t", "value": "tw5947pt1fop5t"},{"name": "vb5qtk37fmk31v1u", "value": "vb5qtk37fmk31v1u"},{"name": "eyuzd4nv34e17db2", "value": "eyuzd4nv34e17db2"},{"name": "osg53hexfy1w9n1", "value": "osg53hexfy1w9n1"},{"name": "poz1nrd1pe1a7b9", "value": "poz1nrd1pe1a7b9"},{"name": "8h21271ae2ed9", "value": "8h21271ae2ed9"},{"name": "mu1g5xfrormjllg", "value": "mu1g5xfrormjllg"},{"name": "y6hyevbo8j960y2l", "value": "y6hyevbo8j960y2l"},{"name": "v6xp3tatg419jom", "value": "v6xp3tatg419jom"},{"name": "yl7vowutfypcor", "value": "yl7vowutfypcor"}}]
}
],
"actionButton": {
"name": "My Button",
"label": "My Action Button",
"style": "secondary"
},
"url": "http://callback.url.com"
}
]
Information on your n8n setup
- n8n version: Cloud, so last I guess
- Database (default: SQLite): default
- n8n EXECUTIONS_PROCESS setting (default: own, main): Unsure
- Running n8n via (Docker, npm, n8n cloud, desktop app): Cloud
- Operating system: Not relevant… but windows
Please let me know if something else is needed to solve this.