Is there a way of converting XML to JSON with reference to a schema.
Lets say a part of the xsd is as below:
<xs:complexType name="RegionStateResultType">
<xs:sequence>
<xs:element name="RegionOrState" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="RegionOrStateCode" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="PinCode" type="xs:integer" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
and the xml is:
<RegionOrStateInfo>
<RegionOrState>Tochigi</RegionOrState>
<RegionOrStateCode>09</RegionOrStateCode>
<PinCode>12345</PinCode>
</RegionOrStateInfo>
On Using XMLtoJSON conversion Policy , if we set RecognizeNumber as 'true' then resulting json is:
{
"RegionOrState": "Tochigi",
"RegionOrStateCode": "09" ,
"PinCode":12345
},
{
"RegionOrState": "Tokushima",
"RegionOrStateCode": 36 ,
"PinCode":12345
}
If RecognizeNumber is set as 'false' then the resulting json is:
{
"RegionOrState": "Tochigi",
"RegionOrStateCode": "09" ,
"PinCode": "12345"
},
{
"RegionOrState": "Tokushima",
"RegionOrStateCode": "36" ,
"PinCode": "12345"
}
The required json is:
{
"RegionOrState": "Tochigi",
"RegionOrStateCode": "09" ,
"PinCode": 12345
},
{
"RegionOrState": "Tokushima",
"RegionOrStateCode": "36" ,
"PinCode": 12345
}
Any way of achieving this?
Has anyone used JSONSchema and is there a way for the converter to refer to a schema and then do the translation?
I also faced some issues with single element arrays in XML to JSON conversion. Thinking is JSONSchema can be of some help