Issue while processing webhooks that have arrays of string values
We use webhooks to add Leads, Calls, and CallAIAnalytics. Each different source of data and different JSON format.
First 2 cases work as expected using default business process to parse webhooks
But webhooks for 3rd case for AI analytics from calls is sending JSON with arrays of text fields instead of concatenated text field.
So we are encountering a critical type casting error when processing incoming data from the webhook using the Newtonsoft.Json library in a .NET environment.
Context:
- Data is being received via a webhook payload.
-
The relevant data section in the JSON payload is structured as an array of strings (a list of mistakes/notes):
JSON
{ // ... other fields "UsrEmployeeMistakes": [ "Mistake 1 detail.", "Mistake 2 detail." ], // ... }
- I am trying to map this value to the column
<strong>UsrEmployeeMistakes</strong>within the entity<strong>UsrResidentAI</strong>.
The Technical Error:
When the system attempts to process the incoming JSON array, it throws a type casting exception:
An error occurred while setting the column value. ColumnName: UsrEmployeeMistakes. EntityName: UsrResidentAI. Exception: Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.
Analysis:
The webhook sends an array, which Newtonsoft.Json correctly parses as a <strong>JArray</strong>. However, the column UsrEmployeeMistakes (or the underlying property/setter) seems to be expecting a simple, single JSON element (JToken), possibly because it's configured to store a single string/text field in the database rather than a collection or a native JSON type.
My Question:
Given that I cannot control the array format from the incoming webhook:
What is the most robust way to handle this conversion in my processing logic?
I am looking for the best practice and no-code or low-code is preferable.
Thank you
Leo
Like