Author |
Message
|
venkat_chekka |
Posted: Thu Aug 13, 2015 6:59 am Post subject: XML Blank filed convert into JSON Null filed issue |
|
|
Apprentice
Joined: 14 Apr 2006 Posts: 37
|
Hi,
I have some blank XML fields in the input message when use below ESQL statement to convert entire XML message into JSON getting issues with Blank fields.
-- to convert entire XML message into JSON
SET OutputRoot.JSON.Data=InputRoot.XMLNSC.
Here is my sample XML field--><field/>
Above filed is going as "field":{} in JSON output message instead of JSON Null data type like "field" : null.
I did convert this field as JSON null field manually after converting entire message into JSON format.
SET OutputRoot.JSON.Data.NullValue VALUE=NULL;
I can have more fields like this in the input message which are dynamically changes each time.
How can we change these BLANK XML fields into JSON Null fields automatically?
Thanks,
Venkat. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Aug 13, 2015 7:08 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
|
Back to top |
|
 |
venkat_chekka |
Posted: Thu Aug 13, 2015 7:23 am Post subject: |
|
|
Apprentice
Joined: 14 Apr 2006 Posts: 37
|
Above link is going here
"IBM Integration Bus 9.0.0>Reference>Message flow development>Transformation interfaces>ESQL reference>ESQL functions>Complex ESQL functions>SELECT function"
But I am looking answer for different JSON Null field related issue and I am using Broker v 8.0.0.5 |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Aug 13, 2015 7:43 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Yes, the link points to the select function.
That is where I meant it to point. |
|
Back to top |
|
 |
venkat_chekka |
Posted: Thu Aug 13, 2015 11:56 am Post subject: |
|
|
Apprentice
Joined: 14 Apr 2006 Posts: 37
|
Which is not solve my problem.
I am talking about different issue but that link is talking about different context  |
|
Back to top |
|
 |
Vitor |
Posted: Fri Aug 14, 2015 4:18 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
venkat_chekka wrote: |
Which is not solve my problem. |
Really?
venkat_chekka wrote: |
I am talking about different issue but that link is talking about different context  |
How so? Why do you think that's not a potential solution to your problem? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Aug 14, 2015 4:47 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
It is possible to write the transformation you want using a SELECT function.
It is very hard, I admit.
Recursively traversing a tree is an algorithm that should have been taught or at least discussed in your programming education.
There are also several implementations in ESQL buried in these forums somewhere. |
|
Back to top |
|
 |
maurito |
Posted: Mon Aug 17, 2015 2:06 am Post subject: Re: XML Blank filed convert into JSON Null filed issue |
|
|
Partisan
Joined: 17 Apr 2014 Posts: 358
|
venkat_chekka wrote: |
sample XML field--><field/>
Above filed is going as "field":{} in JSON output message instead of JSON Null data type like "field" : null.
|
the xml field <field/> is not null, it contains a 0 ( zero ) length string, so the creation of the json is correct.
it would be a different matter if your field was
<field xsi:nil="true" /> or if the field did not exist at all in your xml |
|
Back to top |
|
 |
poppy123 |
Posted: Mon Sep 17, 2018 11:17 pm Post subject: |
|
|
Newbie
Joined: 17 Sep 2018 Posts: 2
|
I have a field "<field xsi:nil="true" />" in my XML message , How can i change to JSON Null field using ESQL ?
Thanks |
|
Back to top |
|
 |
timber |
Posted: Tue Sep 18, 2018 12:43 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
See https://www.ibm.com/support/knowledgecenter/en/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ad67010_.htm
When validation is enabled, XMLNSC will automatically convert xsi:nil=true into a NULL value in the message tree. But only if the field is marked as 'nillable'. So you might not need any ESQL for this.
Try this:
- Set the Domain property on the input node to XMLNSC
- Create an XSD model for your XML input format (if you do not already have one)
- In the XSD, ensure that the element definition 'field' is marked with xsd:nillable="true"
- Set the 'Validation' property on the input node to 'Content and Value'
In theory, XMLNSC will create the NULL values automatically, and JSON will produce the correct output. |
|
Back to top |
|
 |
poppy123 |
Posted: Tue Sep 18, 2018 2:06 am Post subject: |
|
|
Newbie
Joined: 17 Sep 2018 Posts: 2
|
timber wrote: |
See https://www.ibm.com/support/knowledgecenter/en/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ad67010_.htm
When validation is enabled, XMLNSC will automatically convert xsi:nil=true into a NULL value in the message tree. But only if the field is marked as 'nillable'. So you might not need any ESQL for this.
Try this:
- Set the Domain property on the input node to XMLNSC
- Create an XSD model for your XML input format (if you do not already have one)
- In the XSD, ensure that the element definition 'field' is marked with xsd:nillable="true"
- Set the 'Validation' property on the input node to 'Content and Value'
In theory, XMLNSC will create the NULL values automatically, and JSON will produce the correct output. |
I have the following set in the XSD:
<xs:element type="xs:string" name="field" minOccurs="0" nillable="true"/>
I have also followed exactly the the steps mentioned , and have set the following in the ESQL :
SET OutputRoot.JSON.Data = InputRoot.XMLNSC;
The message received is : field":{"nil":true} but the expected is {"field":null}
Thank you |
|
Back to top |
|
 |
timber |
Posted: Tue Sep 18, 2018 3:51 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
The message received is : field":{"nil":true} but the expected is {"field":null} |
Yes - unfortunately it looks as if XMLNSC no longer works as I described. I think your only option is to write a recursive ESQL algorithm to walk the tree and replace xsi:nil child attributes with a NULL value. |
|
Back to top |
|
 |
|