I am using HTTP binding to receive JSON formatted data and using JSONPATH transformation in my channel definition as state transformation.
That’s all working fine with one exception:
In the JSON response there is an optional element; in some responses the element is included and in some it is missing.
If the element is included, the transformation is working fine and any linked item is updated accordingly.
However if the element is missing in the response, I see an error message in the log and the item is not updated.
My aim is, that in case the optional element is missing within the JSON, that the item is still updated with an empty value, as otherwise the item would have an outdated state.
Question: Is this possible at all with JSONPATH transformation or is there another way you can recommend to handle optional elements within JSON data.
I don’t know what you are doing with JSONPATH, you’ve not shown us. If the element is missing, it will blow up, which is what you are trying to avoid.
Do the whole business in one JS transform without using JSONPATH.
I have a 24.000 character JSON string and I wanted to only pass the relevant part of the JSON to the JS transformation; therefore I wanted to combine JSON & JS transformation.
But will try your advice and only do JS.