Question

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***

Comments

Keep up to date on this post and subscribe to comments

June 19, 2019 - 5:02am

Hi Aparna,

@(Pega-RULES:Page).pxConvertPageToString(tools, myStepPage, "json")  should work.

Regards,
Ujjwal

June 19, 2019 - 5:56am
Response to UjjwalShukla_GCS

HI Ujjwal,

Thanks for replying. Couple of questions here - is this a call function in activity step. And what will be myStepPage?

June 19, 2019 - 3:15pm

Hi Ujjwal,

Would appreciate your comments on this.

Thanks

Aparna

June 20, 2019 - 2:06am
Response to AparnaGopakumar


Here StepPage should be the clipboard page that you would like to convert to JSON.

Hope this helps
Regards,
Ujjwal

June 19, 2019 - 4:43pm

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://community1.pega.com/community/pega-support/question/convert-clipboard-page-andor-xml-json

Hope it might help you.

Regards,

Mahesh M

June 21, 2019 - 2:33am

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

June 24, 2019 - 2:34am
Response to AparnaGopakumar

Hi Aparna,

This is expected and can be consumed/parsed by connectors

Regards,
Ujjwal

June 24, 2019 - 5:31am
Response to UjjwalShukla_GCS

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

June 24, 2019 - 6:38am
Response to AparnaGopakumar

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

June 24, 2019 - 8:29am
Response to VinayReddy7

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

June 24, 2019 - 7:12am
Response to AparnaGopakumar

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

June 24, 2019 - 8:46am
Response to UjjwalShukla_GCS

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

June 24, 2019 - 9:04am
Response to AparnaGopakumar

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?

 

June 26, 2019 - 2:21am
Response to AparnaGopakumar

Hi Ujjwal,

Can you please guide me on this.

Thanks

Aparna