Question
TCS
IN
Last activity: 26 Jun 2019 2:21 EDT
Converting Pagelist contents to JSON
Is it possible to convert pagelist contents to JSON format? My needs are with respect to Service Rest output, which is to be shown in JSON format.
Pega version - 7.2
***Edited by Moderator: Lochan to update platform capability tags***
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
IN
Hi Aparna,
@(Pega-RULES:Page).pxConvertPageToString(tools, myStepPage, "json") should work.
Regards,
Ujjwal
-
Rahul Choudhary
TCS
IN
HI Ujjwal,
Thanks for replying. Couple of questions here - is this a call function in activity step. And what will be myStepPage?
TCS
IN
Hi Ujjwal,
Would appreciate your comments on this.
Thanks
Aparna
Pegasystems Inc.
IN
Here StepPage should be the clipboard page that you would like to convert to JSON.
Hope this helps
Regards,
Ujjwal
Pegasystems Inc.
US
Hi Aparna,
As your requirement is in REST Service i would suggest you to go through the below discussion which talks about converting clipboard page to json(without pxObjClass) and you can write custom code accordingly to achieve it for Page List.
https://collaborate.pega.com/discussion/convert-clipboard-page-andor-xml-json
Hope it might help you.
Regards,
Mahesh M
TCS
IN
In the Response field of Method tab (of RULE-SERVICE-REST) I have given the Map From as JSON and Map from Key as the pagelist. And the service is providing response as per attached pic.
The data type of response is java.lang.string. Is this expected? I was hoping for JSON object as response. This JSON object has to be given to another service as input.
Thanks,
Aparna
Pegasystems Inc.
IN
Hi Aparna,
This is expected and can be consumed/parsed by connectors
Regards,
Ujjwal
TCS
IN
Hi Ujjwal,
Thanks for your response. May I ask you one more question?
Hi Ujjwal,
Thanks for your response. May I ask you one more question?
The response needs to be appended with a text. In this fashion : {
"ReqResults": [
{
"CaseID": "abc",
"xyz": "abc",
"Year": "abc"
}]
}
What can I do to get this ReqResults? I have gone through similar posts but could not achieve it.
Thanks
Aparna
Pegasystems Inc.
IN
Hi Aparna,
Could you please post here your current structure.If you have ReqResults on step page that you are passing to function then will get above mentioned structure automatically.
Note : If you don't have following pagelist ReqResults and if you want to append it additionally to Json String then you have to format your string with concatenate operator manually.
Regards,
Vinay
TCS
IN
Hi Vinay,
The current structure is -
{"CaseID":"abc","xyz":"abc","Year":"abc"}
And I want the structure in the following manner -
Hi Vinay,
The current structure is -
{"CaseID":"abc","xyz":"abc","Year":"abc"}
And I want the structure in the following manner -
"ReqResults": [
{
"CaseID": "abc",
"xyz": "abc",
"Year": "abc"
}]
Basically I want to add the text "ReqResults" to the json. Please find attached a sample of current results. The results are in pagelist and Map From key is that pagelist and Map From as JSON (for REST Service)
How could I format the JSON string from Rest service activity?
Thanks
Aparna
Pegasystems Inc.
IN
Hi Aparna,
Result out of function is a string. You can just append the string but if the structure becomes invalid JSON then Parser would fail
--Ujjwal
TCS
IN
Hi Ujjwal,
The REST service invokes the activity which sets the results in pagelist. Since Map From is JSON, the results are converted into JSON format. So in order to append the string, it should be after mapping to json? If this is right, can it be done in the service activity itself? Sorry to sound so naive, but I'm new at this.
Thanks
Aparna
TCS
IN
My thoughts - this append cannot be achieved in the service activity because at this stage the results are in pagelist and a text cannot be added to pagelist property. So that leaves the formating to be done post-mapping. How can I do this?
TCS
IN
Hi Ujjwal,
Can you please guide me on this.
Thanks
Aparna