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:
Primary.JSONResponse.ID
Primary.JSONResponse.Name
Primary.JSONResponse.Company

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.

Solution:



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.

Question:

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
https://www.howtopega.info/2020/04/how-to-parse-json-which-has-spaces-in.html

5 comments:

  1. where have you configured the clipboard page JSONResponse

    ReplyDelete
  2. where have you configured the clipboard page JSONResponse

    ReplyDelete
  3. another efficient approach is by using JSON Data Transforms which are automatically created by pega at the time of creating REST integration.

    ReplyDelete
  4. Thanks for providing good information.

    ReplyDelete
  5. How about if there is a Page property in the Response

    ReplyDelete


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