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 » Issue while passing JSON tree containing List. Item is added

Post new topic  Reply to topic
 Issue while passing JSON tree containing List. Item is added « View previous topic :: View next topic » 
Author Message
PBS12
PostPosted: Tue Aug 20, 2019 7:34 am    Post subject: Issue while passing JSON tree containing List. Item is added Reply with quote

Newbie

Joined: 12 Nov 2018
Posts: 9

Hi,

I am facing one issue while passing over JSON tree containing list. I see at end Item{} is added instead of [{}] for array elements.

I know, the way IIB considers array is different.

But I don't want to copy individual array elements. How can I do whole JSON message copy containing array without adding Item? Is there any way to do it?


e.g. In my current scenario I am saving Input JSON tree in some Environment variable as I want to save it for later use. like below.
Code:

CREATE LASTCHILD OF Environment.Variable DOMAIN('JSON') TYPE Name NAME 'InputData';

SET Environment.Variables.InputData = InputRoot.JSON.Data.SomeRequest;



{
SomeRequest:
{
"ABC":"123",
"PQR":"456"
"someArray":
{
"ele1":"value1",
"ele2":"value2"
}
{
"ele1:"value3",
ele2:"value4"
}
}
}

While passing to end system I am doing below thing.
Code:
SET OutputRoot.JSON.Data=Environment.Variables.InputData;


At end system, They are expecting data like
{
"ABC":"123",
"PQR":"456"
"someArray":[
{
"ele1":"value1",
"ele2":"value2"
}
{
"ele1:"value3",
ele2:"value4"
}]
}


But what they are receiving is-
{
"ABC":"123",
"PQR":"456"
"someArray":
{
Item
{
"ele1":"value1",
"ele2":"value2"
}
Item
{
"ele1:"value3",
ele2:"value4"
}
}
}


If I declare array and copy individual element it works but don't feel its efficient way.

Any suggestions please?

IIB Version - 9.0.0.7

Thanks,
PBS12
Back to top
View user's profile Send private message
PBS12
PostPosted: Tue Aug 20, 2019 11:36 am    Post subject: Issue while passing JSON tree containing List. Item is added Reply with quote

Newbie

Joined: 12 Nov 2018
Posts: 9

Found the way to do it without individual field mapping.
Code:
DECLARE inref REFERENCE TO Environment.Variables.InputData.someArray.Item[1];
 WHILE LASTMOVE(inref)=TRUE DO
          SET OutputRoot.JSON.Data.someArray[I] = inref;
             -- Move the dynamic reference to the next item in the array
             MOVE inref NEXTSIBLING;
             SET I =I+1;
      END WHILE;



This will not add Item element and no need to do individual field mapping.
Back to top
View user's profile Send private message
timber
PostPosted: Fri Aug 23, 2019 12:45 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

Glad you got it working.

You could do this copy in a single line of ESQL if you make sure to preserve the field types in the message trees at every stage. I can see that you are using DOMAIN('JSON') when creating the Environment subtree. But I think you are probably copying the data to some other intermediate tree that is not owned by the JSON parser. That will clear all of the field types and produce exactly the ersult that you describe.

btw - for future reference, a FOR loop is easier for this scenario. I don't understand why people insist on using WHILE for simple iteration over an array.
Back to top
View user's profile Send private message
PBS12
PostPosted: Fri Aug 23, 2019 11:12 am    Post subject: Issue while passing JSON tree containing List. Item is added Reply with quote

Newbie

Joined: 12 Nov 2018
Posts: 9

Thanks for your inputs. Will try to use for loop in future.
Back to top
View user's profile Send private message
rekarm01
PostPosted: Mon Aug 26, 2019 6:27 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

PBS12 wrote:
Code:
WHILE LASTMOVE(inref)=TRUE DO

Adding "= TRUE" (or "IS TRUE") to a BOOLEAN expression is usually redundant, and unnecessary; "LASTMOVE(inref)" works just as well here all by itself, and can make the code a little easier to read.

timber wrote:
btw - for future reference, a FOR loop is easier for this scenario. I don't understand why people insist on using WHILE for simple iteration over an array.

FOR loops are great for simple iteration over a single array, but I always have to double-check the syntax when using it, because the AS clause parameters in a FOR loop are reversed, compared to the AS clause parameters in other ESQL statements and functions:

It's still quite useful, but probably a little more confusing than it needs to be.

But if the message flow needs to iterate over two arrays, (for example, to copy contents from an input array to an output array), then it still needs to create loop variables for the second array.

And one thing that FOR loops are not good for, (nor reference variables in general), is deleting elements from an array.
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 » Issue while passing JSON tree containing List. Item is added
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.