Reputation: 55
I am using BizTalk pipeline with JSON encoder to convert XML to JSON . I have created the XSD but the JSON generated has #text instead of just a value for my elements.
Any ideas what I'm doing wrong?
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://BookingEngine.Schemas.JSONSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" name="affiliate_reference_id" type="xs:unsignedShort" />
<xs:element minOccurs="1" name="hold" type="xs:boolean" />
<xs:element minOccurs="1" maxOccurs="unbounded" name="rooms">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" name="email" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="1" maxOccurs="unbounded" name="payments">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" name="type" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="1" name="affiliate_metadata" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
is converted to the following JSON
{
"affiliate_reference_id": {
"#text": "4480"
},
"hold": {
"#text": "false"
},
"rooms": [
{
"email": "[email protected]"
}
],
"payments": [
{
"type": "customer_card"
}
]
}
expected results would be
{
"affiliate_reference_id": "4480",
"hold": "false",
"rooms": [
{
"email": "[email protected]"
}
],
"payments": [
{
"type": "customer_card"
}
]
}
Any idea why the #text is popping up and how to remove it? What do I need to change in my XSD schema?
Upvotes: 1
Views: 1378
Reputation: 14471
I created a pipeline with a JSON encoder and had this same issue.
The secret is you need to add an XML encoder before the JSON encoder in your pipeline. Yes, it's odd.
Create a schema with the correct data types for the JSON results you want. Add that schema to the XML encoder document schema property. The schema allows you to control how the JSON encoder works.
Note: XML requires a single root node but JSON does not. In your JSON assembly schema create a root node with any name you like. In the JSON encoder there's a check box to remove the root node enclosing the payload.
Javascript data types are not the same as XML (such as dates) so some translation may be needed.
Upvotes: 1
Reputation: 55
I added a custom biztalk pipeline and used json newton soft nuget package .
Upvotes: 0
Reputation: 11
I've the same result in c# when using Newtonsoft. The #text nodes are added when they have a different namespace than the root-namespace because in JSON it becomes an object with a text and a attribute namespace.
Upvotes: 1