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 » Accessing JSON elements via ESQL

Post new topic  Reply to topic
 Accessing JSON elements via ESQL « View previous topic :: View next topic » 
Author Message
anurag.munjal
PostPosted: Thu May 04, 2017 12:43 am    Post subject: Accessing JSON elements via ESQL Reply with quote

Voyager

Joined: 08 Apr 2012
Posts: 97

So, the requirement is pretty simple:

input message:
Code:
{"body": {"SomeRandomName":"SomeRandomValue"}}


Or
Code:
{"body": {"SomeRandomName":1}}



We need to extract the below from this JSON and store into esql char var.

I going crazy as am unable to do it..
can you please help??

i have tried stuff like:
Code:
   DECLARE AttrInfo CHARACTER InputRoot.JSON.Data.body.Item[1];

      DECLARE AttrInfo CHARACTER InputRoot.JSON.Data.body.Item[1].*;



Code:
      DECLARE AttrInfo CHARACTER InputRoot.JSON.Data.body;


can you folks help me get this single line of code set up please?

Using IIB 10.0.04.

I tried this as well,
Code:
SET outputroot.JSON.Data.AttrName = InputRoot.JSON.Data.body;


it gave me this output json in outputroot:
Code:
AttrName .SomeRandomName=1


All i need is a way to extract the JSON attribute SomeRandomName and its value!
_________________
- Anurag
------------------------
Be Simple, Be Happy
Back to top
View user's profile Send private message
martinb
PostPosted: Thu May 04, 2017 2:20 am    Post subject: Reply with quote

Master

Joined: 09 Nov 2006
Posts: 210
Location: UK

Hi

Firstly note that "Item[n]" is used in IIB's JSON domain to represent JSON array data. Your example JSON is object data.

To get the value of
Code:
{"body": {"SomeRandomName":"SomeRandomValue"}}

without knowing the name of JSON "SomeRandomName" I'd use
Code:
SET value = InputRoot.JSON.Data.body.*[>]


To get the actual name of JSON "SomeRandomName" I'd use
Code:
SET name= FIELDNAME(InputRoot.JSON.Data.body.*[>])


HTH
Back to top
View user's profile Send private message
anurag.munjal
PostPosted: Thu May 04, 2017 3:24 am    Post subject: Reply with quote

Voyager

Joined: 08 Apr 2012
Posts: 97

martinb wrote:
Hi

Firstly note that "Item[n]" is used in IIB's JSON domain to represent JSON array data. Your example JSON is object data.

To get the value of
Code:
{"body": {"SomeRandomName":"SomeRandomValue"}}

without knowing the name of JSON "SomeRandomName" I'd use
Code:
SET value = InputRoot.JSON.Data.body.*[>]


To get the actual name of JSON "SomeRandomName" I'd use
Code:
SET name= FIELDNAME(InputRoot.JSON.Data.body.*[>])


HTH


Thanks Martin!
I used the below code and it worked!

Code:
      DECLARE AttrName_Name CHARACTER FIELDNAME(InputRoot.JSON.Data.body.*[1]);


This topic can be closed! thank you
_________________
- Anurag
------------------------
Be Simple, Be Happy
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 » Accessing JSON elements via ESQL
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.