I’m trying to send the below payload (JSON) to a REST endpoint, but when I use conventional mapping in BizTalk to build the XML schema, and then use the JSON encoder in a custom pipeline to send it out, it doesn’t include the required array in filters (its a REST call requirement that the filters record is arrayed, even if there’s only 1 filter record within)
{
"busObId": "9343f8800bd7ce14f0bf0a402d9d38be1a25069644",
"filters": [
{
"fieldId": "937905400191ae67dd03ab4b79968fcbaa264b1a75",
"operator": "eq",
"value": "TIER1WEB02"
}
],
"includeAllFields": false,
"includeSchema": false
}
I’ve considered using message assignment to manually write an XML structure, but I can’t figure out how to get the JSON encoder to array the filters element.
Can anyone please advise on how I can ensure that payload is not removing the []
around filters?
2
Answers
Converting XML to JSON using a generic converter will generally not produce the exact JSON that you actually want. That’s because the converter has no idea what format you want, and there’s generally insufficient information in the XML for it to make a correct guess. In particular, if there’s only one filter in the XML, there’s no way the converter can know that there might have been more than one, other than by some out-of-band configuration option supplied to the converter.
There’s at least five classes of solution:
(a) If you’re lucky, your chosen converter tool might provide options to customise the conversion.
(b) If one conversion tool doesn’t produce the output you want, you might find another that does. There are plenty to choose from. But they all suffer from this problem, so it’s unlikely.
(c) you might be able to transform the XML prior to conversion so that the tool does the right thing. (Again, in this case, this is unlikely because there’s no way to differentiate a singleton from a list of length one in XML.)
(d) you can always transform the JSON after conversion to fit the desired format.
(e) it might turn out to be simplest to write the conversion yourself, for example by using XSLT 3.0.
If I were doing it, I would turn to (e). But the right answer for your project might be different.
Make sure that your pipeline has a XML Assembler in the pipeline before the JSON Encoder.
From my blog BizTalk 2013 R2 known bugs, issues & quirks