Describe the problem/error/question
I want to send some data back as a response to an API call. But the data is getting sent as
[
{
"status " : “success”,
"data" : [
{
"name":"......",
"rollno.":"....."
},
{
"name":"......",
"rollno.":"....."
}
]
}
]
// I want to remove the outer most brackets [] and send them directly in {}.
What is the error message (if any)?
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
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system:
Could not figure out the 3rd step. But with {{$json}} , still same (unless i need to change something like in 3rd step.)
Hi @Aarush_Bisht
For this, you can just add a Set Field node before your Respond to Webhook node, and there in the Set Field node you can clarify your whole JSON structure by switching its mode to JSON, and now once that is done, in the Respond to Webhook node you can set Respond With to First Incoming Item so that whatever comes out from the Set Fields node will be sent automatically.
Like this:
There is another way which I do not recommend for large data, but it also works: by directly parsing the JSON in the response body of the response to the webhook node, and there you define your entire JSON, only if it’s short.
something like this:
={{ { "status": $json.status, "data": $json.data } }}
did that but that square bracket is still coming? why is n8n inherently taking it as array?
@Aarush_Bisht Have you seen the output of Respond to Webhook? As this square bracket would not show there, I have personally tested it.
This is what gets in front:
So I think the square brackets would not come. They are only showed in the UI not in the actual requests.
ah yes ! when checking it via ‘respond to webhook’ output after using set fields, it is showing as expected.