Question
Yash Technologies
IN
Last activity: 6 Apr 2017 22:04 EDT
How to parse json data in pega
How to show JSON data from clipboard to UI?
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
US
Would it help if you could put the json contents into a page? If so, I would recommend looking into the AdoptJSON() and getJSON() API calls.
Yash Technologies
IN
Can you tell me the procedure?
Pegasystems Inc.
US
Absolutely. I pulled the following from a java step in the getPageJSONActivity in the PegaSample Application, it takes JSON as a string and writes its contents to a page called SamplePage using AdoptJSON(). It then takes the page and converts its content to a string using getJSON().
String pageContent = "{\"prop1\":\"value1\",\"PG\":{\"A\":{\"pxSubscript\":\"A\",\"prop1\":\"A1\",\"prop2\":\"A2\",\"pxResults\":[{\"pyLabel\":\"Result1\"},{\"pyLabel\":\"Result2\"}]},\"B\":{\"pxSubscript\":\"B\",\"prop1\":\"B1\",\"prop2\":\"B2\"}}}";
ClipboardPage tempPage = null;
try{
tempPage = tools.createPage("@baseclass","SamplePage");
tempPage.adoptJSONObject(pageContent);
} catch(InvalidStreamError e){
oLog.error("ReloadSection:Invalid JSON Stream for data page params : "+e.getMessage());
} catch(Exception e){
oLog.error("ReloadSection:Expection : "+e.getMessage());
}
String streamToShow = tempPage.getJSON(false);
Hope this helps.
Cognizant Technology Solutions
IN
Pegasystems Inc.
US
Amit,
What is the property within the response_GET page that contains the JSON?
Matt
Pegasystems Inc.
US
The easiest way to get the contents into a local string variable if you are using an activity would probably be a property-set. If that is not an option, you can try something like the following, replacing ???? with the name of the property containing the JSON:
ClipboardPage webFormPage = tools.findPage("WebForm");
ClipboardProperty responseJSON = webFormPage.getProperty("response_GET").getProperty("????");
String pageContent = responseJSON.toString();
As always, activities and java within PRPC should only be used when necessary.
Cognizant Technology Solutions
IN
Hi Mathew,
As you suggest me in previous code. I am able to get response from JSON format to clipboard structure in samplePage. Now I don't know how to map these values in UI controls.
I have shared the screen shorts for better understanding.
I have taken the response in local variable
Then I have passed this local variable in pageContent
after this I am able to get a page SamplePage in clipboard with all response property
In red box is new samplePage in clipboard structure
Hi Mathew,
As you suggest me in previous code. I am able to get response from JSON format to clipboard structure in samplePage. Now I don't know how to map these values in UI controls.
I have shared the screen shorts for better understanding.
I have taken the response in local variable
Then I have passed this local variable in pageContent
after this I am able to get a page SamplePage in clipboard with all response property
In red box is new samplePage in clipboard structure
In yellow box is my default response from service
Now please suggest me that how I get these results on UI
Regards,
Amit Goyal
Citicorp Services India Private Limited
IN
Hi Amit,
SamplePage type is classless in clipboard. You have to copy the value to a property in another page "say pyWorkPage / other page which has class type associated to it (Address(Org-Data-Address))". Then you can map the property to the UI control using correct context page as shown below.
Define Page and Class Name in Pages & Classes as shown below
Map the property to UI control as shown below
Please let me know if this helps,
Thanks,
Gowrishankar.
Pegasystems Inc.
US
From your Clipboard structure it looks like you are using a Connector to connect to a Google service, did you already try the JSON response handler?
The screenshot above is a use case in our product, where we are capturing JSON from an external, non PPRC, REST service and mapping it accordingly to a well defined PRPC ClipboardPage.
Otherwise Gowrishankar Ramasamy is correct, the classless-ness of your data is why you can't use it in PRPC with a UI. For situations like this, I have found creating an Activity that references the "SamplePage" ClipboardPage and iterates through the nested structure, setting the only pxObjClass, is sufficient to make the page UI usable again.
Synechron
US
Hi Matt,
Pzexternal qualifier doesn't work with adoptJSONObject. Please do you know how to resolve that issue?
Thanks,
Janaka Perera