BizTalk JSON Deserialize - json

I have to connect a REST service via BizTalk. The service returns a JSON response as shown below. When the BizTalk response port tries to decode the JSON message I get an error about JSON to XML conversion. This error happen because of embedded HTML tags in the JSON Message.
Error:
(There was a failure executing the response(receive) pipeline: "Avansas.Paritus.Suggest.T.JSONReceive, Avansas.Paritus.Suggest.T, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7b2984270a9ffd13" Source: "JSON decoder" Send Port: "Avansas.Ibrahim.Suggest.T.SendPort" URI: "api1.test.com/services/rest"; Reason: Unexpected character encountered while parsing value: <. Path '', line 0, position 0. )
For Example:
As below response message has a label element in JSON. Label element has a text with html tag (City) that's why when BizTalk tries to convert JSON to XML I get an error. I think BizTalk tries to convert JSON as figure 2 but I want to convert it as figure 3.
How can I solve this issue?
Is there any way to passthru transmit on orchestration without any schema?
Figure1
{
"suggestion": [
{
"id": "[31 31 31 30 30 39]",
"label": "Global <b>City</b> 2. Etap Global <b>Cıty</b> ",
"value": "Global <b>City</b> 2. Etap Villaları "
},
{
"id": "[39 33 36 32 35 36]",
"label": "<b>City</b> Aqua Villas Sk. Kuşadası Aydın",
"value": "<b>City</b> Aqua Villas Sk. Kuşadası Aydın"
}
]
}
Figure 2:
<root>
<suggestion>
<id>[31 31 31 30 30 39]</id>
<label>Global
<b>City</b> 2. Etap Global
<b>Cıty</b>
</label>
<value>Global
<b>City</b> 2. Etap Villaları
</value>
</suggestion>
<suggestion>
<id>[39 33 36 32 35 36]</id>
<label>
<b>City</b> Aqua Villas Sk. Kuşadası Aydın
</label>
<value>
<b>City</b> Aqua Villas Sk. Kuşadası Aydın
</value>
</suggestion>
</root>
Figure 3:
<root>
<suggestion>
<id>[31 31 31 30 30 39]</id>
<label>Global
<b>City</b> 2. Etap Global
<b>Cıty</b>
</label>
<value>Global
<>City</b> 2. Etap Villaları
</value>
</suggestion>
<suggestion>
<id>[39 33 36 32 35 36]</id>
<label>
<b>City</b> Aqua Villas Sk. Kuşadası Aydın
</label>
<value>
<b>City</b> Aqua Villas Sk. Kuşadası Aydın
</value>
</suggestion>
</root>
Also my service can be return xml response and when i try to handle xml response a get an below error.
XML Error
There was a failure executing the response(receive) pipeline: "Microsoft.BizTalk.DefaultPipelines.XMLReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Source: "XML disassembler" Send Port: "aaa.bbb.Suggest.T.SendPort" URI: "https://api1.test.com/services/rest" Reason: Finding the document specification by message type "html" failed. Verify the schema deployed properly
And response xml as shown below
<?xml version="1.0" encoding="UTF-8"?>
<suggestions>
<suggestion>
<id>111011</id>
<label>Global <b>Cıty</b> 1. Etap Vıllaları Sokak</label>
<value>Global Cıty 1. Etap Vıllaları Sokak</value>
</suggestion>
<suggestion>
<id>111009</id>
<label>Global <b>Cıty</b> 2. Etap Vıllaları Sokak</label>
<value>Global Cıty 2. Etap Vıllaları Sokak</value>
</suggestion>
</suggestions>

Using this schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://BizTalk_Server_Project1.JSONSchema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="suggestion">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="id" type="xs:string" />
<xs:element minOccurs="0" name="label" type="xs:string" />
<xs:element minOccurs="0" name="value" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And this pipeline:
Produces this message:
<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.JSONSchema1">
<suggestion>
<id>[31 31 31 30 30 39]</id>
<label>Global <b>City</b> 2. Etap Global <b>Cıty</b> </label>
<value>Global <b>City</b> 2. Etap Villaları </value>
</suggestion>
<suggestion>
<id>[39 33 36 32 35 36]</id>
<label><b>City</b> Aqua Villas Sk. Kuşadası Aydın</label>
<value><b>City</b> Aqua Villas Sk. Kuşadası Aydın</value>
</suggestion>
</ns0:Root>

Related

XSD Schema for the JSON Body

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?
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.

BizTalk JSON encoder pipeline generating incorrect JSON object from XSD

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": "john#example.com"
}
],
"payments": [
{
"type": "customer_card"
}
]
}
expected results would be
{
"affiliate_reference_id": "4480",
"hold": "false",
"rooms": [
{
"email": "john#example.com"
}
],
"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?
‪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. ‬
I added a custom biztalk pipeline and used json newton soft nuget package .
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.

SoapUI generates JSON property for namespace

I generate a WADL with CXF as described in CXF – Missing WADL method parameter element types with JSON JAX-RS services.
I tried to generate the JSON request body in SoapUI ("Recreates a default representation from the schema"), but I get the wrong JSON including namespace.
Code:
CXF configuration:
<bean id="wadlGenerator" class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
<property name="linkJsonToXmlSchema" value="true" />
</bean>
<jaxrs:server address="/rest/1" id="test" staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="testResource" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" />
<ref bean="wadlGenerator" />
</jaxrs:providers>
</jaxrs:server>
WADL:
<?xml version="1.0"?>
<application xmlns:prefix1="http://www.test.com/test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://wadl.dev.java.net/2009/02">
<grammars>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.test.com/test" targetNamespace="http://www.test.com/test" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:import/>
<xs:element name="testModel" type="testModel"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.test.com/test" targetNamespace="http://www.test.com/test" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:complexType name="testModel">
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</grammars>
<resources base="http://localhost:8080/test-app/services/rest/1">
<resource path="/test">
<method name="POST">
<request>
<representation mediaType="application/json" element="prefix1:testModel"/>
</request>
<response status="204"/>
</method>
</resource>
</resources>
</application>
JSON:
{
"#xmlns:test": "http://www.test.com/test",
"id": "?",
"name": "?"
}
Is that a bug/missing feature of SoapUI or is there something wrong with my WADL?

XML validation not working

i have one XML file and one XSD file. i in xsd in set cost as integer value but its not working . i don't know problem in my linking xsd file or where. why it doesn't show any error or warning. if i check this with online validation tool it show an error can anyone help me.
This is my XML code.
<?xml version="1.0" encoding="UTF-8"?>
<cupcakes xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com cupcake.xsd">
<item>
<name>Luscious Vanilla</name>
<flavour>Vanilla</flavour>
<colour>Brown</colour>
<energy> 410 KJ </energy>
<cost> $0.90 sdfgsdfg</cost>
</item>
<item>
<name>Chocolate Hazelnut</name>
<flavour>Chocolaty</flavour>
<colour>Coffe</colour>
<energy> 350 KJ </energy>
<cost> $2 </cost>
</item>
<item>
<name>Risch Red Velvet</name>
<flavour>Red Velvet</flavour>
<colour>Red</colour>
<energy> 105 CAL </energy>
<cost> $5 </cost>
</item>
<item>
<name>Classic straberry</name>
<flavour>Straberry</flavour>
<colour>Pink</colour>
<energy> 110 CAL </energy>
<cost> $6 </cost>
</item>
<item>
<name>Lemon Drop</name>
<flavour>Lemon</flavour>
<colour>Yellow</colour>
<energy> 510 KJ </energy>
<cost> $12 </cost>
</item>
</cupcakes>
and this is my XSD file .
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="cupcakes">
<xs:complexType>
<xs:sequence>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="flavour" type="xs:string"></xs:element>
<xs:element name="colour" type="xs:string"></xs:element>
<xs:element name="energy" type="xs:string"></xs:element>
<xs:element name="cost" type="xs:integer"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Your cost items are set to be integer but you are using floating point.
And you are using '$' which is not an integer.
Try this tool: http://xmlvalidation.com

XML validation fails with error "Top level is not completed"

I've got what seems like a very simple example of an xsd and xml file where the xml file does not validate.
Copies of the two files are below.
The first xml element with id = 'fixMe' gets an error that says
Top level is not completed.
Valid xml document must have a root tag
If I remove its id attribute or use "idx" instead of "id", it's fine. But I can't figure out why. 'id' should be a valid attribute.
Any insight appreciated.
XML:
<question id="fixMe" />
<question idx="ok"/>
<question />
XSD:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="perceptive.com/mi/analysis"
xmlns="perceptive.com/mi/analysis"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="test" type="test"/>
<xs:complexType name="test">
<xs:sequence minOccurs="1" maxOccurs="10">
<xs:element name="question" type="question_type"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="question_type">
<xs:attribute name="idx" type="xs:string" use="optional"/>
<xs:attribute name="id" type="xs:string" use="optional"/>
</xs:complexType>
</xs:schema>
An XML document cannot be valid until it is well-formed.
So you should specify a root tag in XML document, e.g.:
<root>
<question id="fixMe" />
<question idx="ok"/>
<question />
</root>