|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
![Reply to topic](templates/DAJ_Glass/images/lang_english/reply.gif) |
|
Referencing JSON Array Object Directly |
« View previous topic :: View next topic » |
Author |
Message
|
arun_ace |
Posted: Mon Dec 18, 2023 9:48 am Post subject: Referencing JSON Array Object Directly |
|
|
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 |
|
![](templates/DAJ_Glass/images/spacer.gif) |
fjb_saper |
Posted: Tue Dec 19, 2023 5:22 am Post subject: Re: Referencing JSON Array Object Directly |
|
|
![](images/avatars/gallery/misc/2.gif) 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 ![](images/smiles/innocent.gif) _________________ MQ & Broker admin |
|
Back to top |
|
![](templates/DAJ_Glass/images/spacer.gif) |
mgk |
Posted: Tue Dec 19, 2023 7:02 am Post subject: |
|
|
![](images/avatars/gallery/Star Wars/movie_star_wars_emperors_guard.gif) 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 |
|
![](templates/DAJ_Glass/images/spacer.gif) |
|
|
![Reply to topic](templates/DAJ_Glass/images/lang_english/reply.gif) |
|
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
|
|
|
|