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 » Transform XML to JSON in WMB

Post new topic  Reply to topic
 Transform XML to JSON in WMB « View previous topic :: View next topic » 
Author Message
cadenza
PostPosted: Wed Sep 21, 2011 7:30 am    Post subject: Transform XML to JSON in WMB Reply with quote

Apprentice

Joined: 01 Jun 2004
Posts: 48

Hi,

I am using WMB v7 Fix3. Trying out a simple XML to JSON Conversion obtained from this link.

http://www.thomasfrank.se/xml_to_json.html

My flow is simple MQInput -> Compute -> MQOutput

The objective is just to see the transformation and hence did not use any HTTP nodes. I will have to use it once I am able to get a better handle on the transformation coding.

Code:


      DECLARE RF_IN_Animals    REFERENCE TO InputRoot.XMLNSC.animals;
      DECLARE RF_IN_Dog      REFERENCE TO RF_IN_Animals.dog;
      DECLARE RF_IN_Cat      REFERENCE TO RF_IN_Animals.cat;
      
      CREATE FIELD OutputRoot.JSON.Data.animals IDENTITY (JSON.Object)animals;
      CREATE FIELD OutputRoot.JSON.Data.animals.dog IDENTITY (JSON.Array)dog;
      CREATE LASTCHILD OF OutputRoot.JSON.Data.animals.dog TYPE NameValue NAME FIELDNAME(RF_IN_Dog.*[1]) VALUE FIELDVALUE(RF_IN_Dog.*[1]);
      CREATE LASTCHILD OF OutputRoot.JSON.Data.animals.dog TYPE NameValue NAME FIELDNAME(RF_IN_Dog.*[2]) VALUE FIELDVALUE(RF_IN_Dog.*[2]);
      MOVE RF_IN_Dog NEXTSIBLING REPEAT TYPE NAME;
      CREATE LASTCHILD OF OutputRoot.JSON.Data.animals.dog TYPE NameValue NAME FIELDNAME(RF_IN_Dog.*[1]) VALUE FIELDVALUE(RF_IN_Dog.*[1]);
      CREATE LASTCHILD OF OutputRoot.JSON.Data.animals.dog TYPE NameValue NAME FIELDNAME(RF_IN_Dog.*[2]) VALUE FIELDVALUE(RF_IN_Dog.*[2]);
      CREATE FIELD OutputRoot.JSON.Data.animals.cat IDENTITY (JSON.Object)cat;
      CREATE LASTCHILD OF OutputRoot.JSON.Data.animals.cat TYPE NameValue NAME FIELDNAME(RF_IN_Cat.*[1]) VALUE FIELDVALUE(RF_IN_Cat.*[1]);



The above code gives me the following result in the output queue

{"animals":{"dog":["Rufus","labrador","Marty","whippet"],"cat":{"name":"Matilda"}}}

The result as per the debugger after the compute node is

{"animals":{"dog":[{"name":"Rufus","breed":"labrador","name":"Marty","breed":"whippet"}],"cat":{"name":"Matilda"}}

Any ideas why the output gets changed when it is put to the queue. Not sure how I can tweak in the code to make it as expected in the website sample.

I think using ROW is an option which I will try next.
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 » Transform XML to JSON in WMB
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.