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 IndexWebSphere Message Broker SupportJson Array Parser Problem

Post new topicReply to topic
Json Array Parser Problem View previous topic :: View next topic
Author Message
Android 23
PostPosted: Wed Jul 12, 2017 10:38 pm Post subject: Json Array Parser Problem Reply with quote

Apprentice

Joined: 27 Mar 2017
Posts: 26

Hi Guys,
I have created JSON array and i have parsed the data in it.
And i can see Output tree structure consists of two results with same fields and data as i expected and when i moved to output node, then i can see only one value instead of two value.

I have tried using FOR and WHILE Loops for it.And same result is displayed all the time.
And output consists of same fields and same data extracted from database to be displayed two times as output.

For Loop

Code:

      DECLARE K INTEGER 1;
--      SET OutputRoot.JSON.Data.Details.userpart TYPE=JSON.Array;
CREATE FIELD OutputRoot.JSON.Data.Details.userpart IDENTITY(JSON.Array) userpart;
      FOR Det AS EV.XMLNSC.data.samp.ResultSet[] DO
         SET OutputRoot.JSON.Data.Details.userpart[K]=Det;

         SET K=K+1;
      END FOR;


While Loop
Code:

   DECLARE i INTEGER 1;
      DECLARE j INTEGER;
       SET j= CARDINALITY(EV.XMLNSC.data.samp.ResultSet[]);
       WHILE i <=j DO
       SET OutputRoot.JSON.Data.samp.Details.Item[i]=EV.XMLNSC.data.samp.ResultSet;
      --
    SET i= i+1;
       END WHILE;


And i tried without using loop and i got extact result as expected
Without loop
Code:

 CREATE FIELD OutputRoot.JSON.Data.Details.userpart IDENTITY(JSON.Array) userpart;
       SET OutputRoot.JSON.Data.Details.userpart.Item[1]=EV.XMLNSC.data.samp.ResultSet[1];
      SET OutputRoot.JSON.Data.Details.userpart.Item[2]=EV.XMLNSC.data.samp.ResultSet[2];



Any errors in loops or did i miss anything in it.

Thanks & Regards,
Android 23.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Jul 13, 2017 4:07 am Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17257

All of these loops use "[<integer>]".

That's essentially an error. Create a Reference , and use Move Next Child.

Otherwise, if your loops have "errors", but they run, then the problem is with your data, or your transformation logic.

We can't help with that, without input data and output results.

A User Trace can help you very easily to troubleshoot your flow and your ESQL.
_________________
Read, Think, Try, Repeat
Back to top
View user's profile Send private message
timber
PostPosted: Thu Jul 13, 2017 1:33 pm Post subject: Reply with quote

Yatiri

Joined: 25 Aug 2015
Posts: 629

I just don't understand why people think it's easier to use a counter and an array reference. For me, using an indexed array is slower, takes more code, and is harder to get right.
I haven't tested this, but this is how I would do it:
Code:
FOR Det AS EV.XMLNSC.data.samp.ResultSet[] DO
    CREATE LASTCHILD OF OutputRoot.JSON.Data.Details.(JSON.Array)userpart FROM Det; 
END FOR;


I will leave it to others to suggest a single-line solution using a SELECT statement. Probably not worth it, when the FOR loop is so simple.
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexWebSphere Message Broker SupportJson Array Parser Problem
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.