Saturday, April 11, 2020

How to parse JSON and map it to Clipboard structure in Pega

How to parse JSON and map it to Clipboard structure in Pega

JSON Employee:

Clipboard Structure:

This can be achieved in multiple ways in Pega. Presenting one of the simple ways  to achieve this via OOTB Rule Utility Function (RUF) : pxConvertStringToPage. Feel free to comment if you have any alternative approach in comments.


Step #1: Take the JSON to be input in the below format (picked it for executing sample JSON).
Local.JSONString = "";
- JSON Data to be assigned to this variable and passed in the next step.
- Please also escape double quote to avoid compilation errors.

Step #2: Invoke pxConvertStringToPage(tools, Primary.JSONResponse, Local.JSONString, "json")
#2.1 Primary.JSONResponse is the page on which we want the parsed data.
#2.2 Local.JSONString is the input JSON Data.
#2.3 JSON is the format that we are expecting to parse. So need to pass it.

Step #3: Execute the activity to see the output page Primary.JSONResponse

As expected, JSON Data is mapped to clipboard structure.


Above one is a simple example, where we parsed JSON and mapped it to Pega Clipboard structure. How about bit more advanced topic : by picking JSON data as below which has spaces in one of the keys? (example: "Company ID" has a space between Company and ID).

Here the challenge is we cannot create a property in Pega with space. Then how can we map it to property in Pega. Any ideas ? Feel free to comment if you have any thoughts around this already?

Answer: Please click on the below link for the answer

No comments:

Post a Comment

HowToPega : All rights reserved and the contents are copyrighted to Pavan Kumar Naidu