1

I have defined a xml scehema below

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
    <xs:element name="Root">
        <xs:complexType>
            <xs:all>
                <xs:element name="bblist">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="item" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:all>
        </xs:complexType>
    </xs:element>
</xs:schema>

I want to generate the Json below using a pipeline.

{
    "bblist":
    [
        "13403"

    ]
}

but the BizTalk pipeline converts it to

{"bblist": "13403"}

Just wondering if my schema is correct. Am I defining the xsd to generate Json arrays correctly?

Lova Chittumuri
  • 2,994
  • 1
  • 30
  • 33
vaughn
  • 49
  • 1
  • 11

1 Answers1

1

There are three issues with your XSD schema

  1. You haven't defined a target Namespace. Which means when it goes through the XML Receive it sets the MessageType to a default set of values which doesn't reference the schema. Which means it might not know which schema to use in the JSON Encoder.

MessageType Root Promoted http://schemas.microsoft.com/BizTalk/2003/system-properties

  1. You have used a <xs:all> rather than a <xs:sequence> in your schema definition. That the JSON Encoder doesn't handle.

If you define your schema as this

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://bblist" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" targetNamespace="http://bblist" vc:minVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" name="bblist">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="1" maxOccurs="unbounded" name="item" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

With a payload of

<ns0:Root xmlns:ns0="http://bblist">
  <bblist>
    <item>item_0</item>
  </bblist>
</ns0:Root>

You get a output of

{
  "bblist": {
    "item": [
      "item_0"
    ]
  }
}

This is closer to your expected JSON, with it making an array of the repeating element.

  1. Your structure is incorrect for the JSON you are expecting as you have the repeat on the item and not on the blist.

If you define your schema as

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://bblist" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" targetNamespace="http://bblist" vc:minVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" name="blist" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

XML is

<ns0:Root xmlns:ns0="http://bblist">
  <blist>blist_0</blist>
</ns0:Root>

JSON is

{
  "blist": [
    "blist_0"
  ]
}
Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
  • I have the same problem but no possibility to add a target namespace because the schema is generated by SAP (IDoc). Do you know other options to "force" an array in the converted JSON in this situation? Thanks, Chris. See: https://stackoverflow.com/questions/68016286/biztalk-xml-to-json-pipeline-force-json-array-even-without-a-schema-target-nam – Chris Jun 17 '21 at 09:09
  • 1
    @Chris You might want to post it as a new question and link to this one and explain why you can't add a namespace. Maybe you can't add it to the SAP schema, but you should be able to create another schema that you then map the SAP message to. – Dijkgraaf Jun 17 '21 at 20:55