Parsing a JSON Response Message that Contains Arrays
When the element is a child element of complex type and the maximum occurrence of this element is unbounded, the schema is not valid. The JSON parser restricts you from extracting multiple instances of an element.
The maximum occurrence of child elements under complex type must be 0 or 1 with the order indicator as choice for the complex type in a schema. When you change the maximum occurrence as 1 to validate the schema, you can extract one instance of the element at a time.
You can use the maximum occurrence as unbounded in the choice order indicator of a complex type in the schema.
Example JSON Response Message
You have the following schema where the complex type element xmlRoot has element name Likes whose maximum occurrence is unbounded:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="xmlRoot">
<xs:complexType>
<xs:all>
<xs:element type="xs:byte" name="Age"/>
<xs:element type="xs:string" name="FirstName"/>
<xs:element type="xs:string" name="Likes" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="xs:string" name="FamilyName"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
You can change the JSON response in the following format:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="xmlRoot">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element type="xs:byte" name="Age"/>
<xs:element type="xs:string" name="FirstName"/>
<xs:element type="xs:string" name="Likes" />
<xs:element type="xs:string" name="FamilyName"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:choice maxOccurs="unbounded"> allows the contents to be repeated one or more times, in any order.
Unnamed Arrays in a Response Message
A REST Web Service Consumer transformation supports unnamed arrays only in a response message but not in a request message. To parse an unnamed array schema defined in the Method Output Definition, the parent element of complexType or simple type array elements must be of name xmlRooot.
In a Rest Web Service Consumer transformation, you must define xmlRoot as the child element of the xmlRoot element with maximum occurs set to unbounded and the elements in unnamed array as child elements of the xmlRoot element.
The following image shows the defined method output for the unnamed array: