skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. Make sure that your pipeline has a XML Assembler in the pipeline before the JSON Encoder.

    QUIRK: THE BIZTALK JSON ENCODER – JSON ARRAY

    Details: JSON Encoder not creating JSON Array for what should be a
    repeating element. This occurs if you don’t have schema deployed that
    matches the XML payload and there is only a single item. See JSON
    Array – BizTalk JSON Encoder

    Work Around: The XML must conform to a
    schema that BizTalk knows about. Use a custom send pipeline that
    contains a XML Assembler pipeline component before the JSON encoder
    pipeline component.

    From my blog BizTalk 2013 R2 known bugs, issues & quirks

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search