Home > OS >  XSD Schema for the JSON Body
XSD Schema for the JSON Body

Time:02-04

I would like to get the XSD schema for the below JSON Body.

[
    {"text": "Hello"},
    {"text": "How are you?"}
]

For instance, if I convert online the above JSON body to XML and then to XSD schema, it gives the below output.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="row">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="text" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

The intent is to use the XSD schema in Informatica Rest web consumer transformation. With the above XSD schema, the JSON body is creating as below, which is not desired request body:

{"row": [
    {"text": "Hello"},
    {"text": "How are you?"}
]}

Is there anyway, I can skip the row tag?

Any help in this regard?

CodePudding user response:

JSON and XML have different data models, which means that lossless round-tripping is generally impossible. If you want to achieve it, you will need to write custom code that understands your specific data. A good tool for this job is XSLT 3.0.

  • Related