Does n8n only response in json array [] and can it return as json object {}? I tried pipedream webhook and it returned as json object. I’m working with a rigid system that expecting json object. When working with n8n webhook the system encountered error below due to json array.
What is the error message (if any)?
Failed to parse the API response: 'Cannot deserialize the current JSON array
(e.g. [1,2,3]) into type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]'
because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\n
To fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change
the deserialized type to an array or a type that implements a collection interface
(e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array.
JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\n
Path '', line 1, position 1.'"
}
I tried to edit the output by removing the bracket but the bracket reinjected instantly upon saved.
Hi @jan , I want my webhook to handle both scenarios but it isn’t possible, using the workflow you can try it, and it need to tweak the Webhook response option to get the correct response of another. I’m on 0.226.2.
The problem is that you configured your Webhook Node with: Respond: When Last Node Finishes" and you then used the “Respond to Webhook Node” instead of configuring the Webhook Node to us the “Respond to Webhook Node” by setting it to: Respond: Using "Respond to Webhook Node".
Additionally did also the response data did not get stringified.
However it makes me wonder without changing the workflow but just webhook response option could result in a vast behavior that “when last node finishes” works without stringify while “using webhook respond node” requires stringify.
That depends on the options.
If you use the same options (no matter if configured on Webhook Node or Respond to Webhook) that it should simply return the data of the node/last node, then n8n takes care of the logic and makes sure the data is returned correctly.
If you configure the Resond to Webhook Node to return specific data, in your above example “Text” then it is on the user to make sure that the data, which is defined in that parameter, is formatted correctly. And in your first example, you mixed strings with objects and that is what JavaScript does in that case, that it returns an object as [object Object].
Thanks Jans for taking time to solve this for me and with the additional explanation , it makes sense now looking at my previous configuration and the output I got.
Glad to hear. There are for sure things in n8n which are not completely obvious in the beginning, and we are constantly trying to make things easier and clearer. But generally, if there is a choice between simplicity and power & flexibility will we choose power & flexibility. Because we do not want to be the most simple tool out there, we rather want to be the most powerful one which sadly also means that it is sometimes harder for people that start to use n8n.