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 » Referencing JSON Array Object Directly

Post new topic  Reply to topic
 Referencing JSON Array Object Directly « View previous topic :: View next topic » 
Author Message
arun_ace
PostPosted: Mon Dec 18, 2023 9:48 am    Post subject: Referencing JSON Array Object Directly Reply with quote

Newbie

Joined: 18 Dec 2023
Posts: 3

Hello All, I am trying REFERENCE function to move the pointer to "ParentId" element which is inside ad Array object(Sets) someting like below, but unable to do it. When I use indexing it works, This ParentID can be in any index not restricted to 2nd object.
DECLARE rInMsgPID REFERENCE TO InputRoot.JSON.Data.Payload.Sets.['ParentID']; --> Doestnt work
DECLARE rInMsgPID REFERENCE TO InputRoot.JSON.Data.Payload.Sets.[2]; --> Works

{
"Payload": {
"Sets": [
{
"EmployeeID": {
"employee": "A08"
}
},
{
"ParentID": {
"Parent": "1",
"Son": "2",
"Sibling": "2"
}
},
{
"MemberId": {
"Member": "22",
"MemberName": "umar"
}
}
]
}
}
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Dec 19, 2023 5:22 am    Post subject: Re: Referencing JSON Array Object Directly Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

arun_ace wrote:
Hello All, I am trying REFERENCE function to move the pointer to "ParentId" element which is inside ad Array object(Sets) someting like below, but unable to do it. When I use indexing it works, This ParentID can be in any index not restricted to 2nd object.
Code:
 
DECLARE rInMsgPID REFERENCE TO InputRoot.JSON.Data.Payload.Sets.['ParentID']; --> Doestnt work
DECLARE rInMsgPID REFERENCE TO InputRoot.JSON.Data.Payload.Sets.[2]; --> Works

{
   "Payload": {
      "Sets": [
         {
            "EmployeeID": {
               "employee": "A08"
            }
         },
         {
            "ParentID": {
               "Parent": "1",
               "Son": "2",
               "Sibling": "2"
            }
         },
         {
            "MemberId": {
               "Member": "22",
               "MemberName": "umar"
            }
         }
      ]
   }
}


That's because you're not doing it right.
First you need to reference the first element:
Code:
DECLARE rInMsgPID REFERENCE TO InputRoot.JSON.Data.Payload.Sets.[1]
#Then you do what you need and move to the next sibling (from memory)
MOVE rInMsgPID NEXT SIBLING NAME TYPE;


First you have to have a reference. Then you can move that reference which ever way you need: Parent, Sibling, FirstChild, LastChild, etc...

Hope this helps
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
mgk
PostPosted: Tue Dec 19, 2023 7:02 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1638

If you look at the documentation you can see that the array syntax does not take a name: https://www.ibm.com/docs/en/app-connect/12.0?topic=reference-esql-field-overview

Due to the way the JSON parser domain creates the tree with an extra "Item" element to represent each array entry this can get a little tricky: https://www.ibm.com/docs/en/app-connect/12.0?topic=parsers-json-parser-domain

If you use a Trace Node and trace ${Root} you will see the shape of the tree that is built for your message with the "Item" element mentioned above

However, something like this should work:

Code:
DECLARE ref3 REFERENCE TO InputRoot.JSON.Data.Payload.Sets.[1];
X: WHILE LASTMOVE(ref3) DO
  IF EXISTS(ref3.ParentID[]) THEN
     LEAVE X;
  END IF;
  MOVE ref3 NEXTSIBLING;
END WHILE;


I hope this helps.
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
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 » Referencing JSON Array Object Directly
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.