ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » XML Blank filed convert into JSON Null filed issue

Post new topic  Reply to topic
 XML Blank filed convert into JSON Null filed issue « View previous topic :: View next topic » 
Author Message
venkat_chekka
PostPosted: Thu Aug 13, 2015 6:59 am    Post subject: XML Blank filed convert into JSON Null filed issue Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Thu Aug 13, 2015 7:08 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

http://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ak05620_.htm
Back to top
View user's profile Send private message
venkat_chekka
PostPosted: Thu Aug 13, 2015 7:23 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Thu Aug 13, 2015 7:43 am    Post subject: Reply with quote

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
View user's profile Send private message
venkat_chekka
PostPosted: Thu Aug 13, 2015 11:56 am    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Fri Aug 14, 2015 4:18 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Fri Aug 14, 2015 4:47 am    Post subject: Reply with quote

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
View user's profile Send private message
maurito
PostPosted: Mon Aug 17, 2015 2:06 am    Post subject: Re: XML Blank filed convert into JSON Null filed issue Reply with quote

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
View user's profile Send private message
poppy123
PostPosted: Mon Sep 17, 2018 11:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
timber
PostPosted: Tue Sep 18, 2018 12:43 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

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
View user's profile Send private message
poppy123
PostPosted: Tue Sep 18, 2018 2:06 am    Post subject: Reply with quote

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
View user's profile Send private message
timber
PostPosted: Tue Sep 18, 2018 3:51 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » XML Blank filed convert into JSON Null filed issue
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.