|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Json Array Parser Problem |
« View previous topic :: View next topic » |
Author |
Message
|
Android 23 |
Posted: Wed Jul 12, 2017 10:38 pm Post subject: Json Array Parser Problem |
|
|
Apprentice
Joined: 27 Mar 2017 Posts: 38
|
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 |
|
 |
mqjeff |
Posted: Thu Jul 13, 2017 4:07 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
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. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
timber |
Posted: Thu Jul 13, 2017 1:33 pm Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
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 |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|