I have a CONNECT REST Service returning me a json response. By creating the classes & properties I have mapped all the response data onto clipboard properties. One of the propertiy value itself is a string in json format. How can I parse this json string & set the name value pairs into sub-properties in that page? Java parsing code requires importing of JSON packages
which throws an error in Pega.
The JSON Response from REST service in SOAP UI is as below:
Note the selectedProviders element in red is the one containing the json string that needs to be parsed. I have shortened the json string so please excuse any sytax errors, but hope u understood what I am looking for
What you call "property value itself is a string in json format" is technically a JSON object inside another objectJ
Since you are on 6.2 SP2, you need to create classes and properties manually. In the example you provided,
selectedProviders would be an embedded page property in the result class. In selectedProvider's page class, you should create text type properties for ts, txnid, network, psc, fipsCountyCode, cmsCountyCode. You don't need to write custom Java for this. JSON data would automatically map to clipboard if your data model is created correctly. Just remember this:
Pega equivalent of JSON object is a Page property.
Pega equivalent of JSON array is a PageList property.
Thanks Praneeth. That helps. But having said that, I am still facing issues. I changed the SelectedProviders property to a pagelist & created all the properties & classes under it as per the json data structure. BUt the entire json sub-object is still being set on the pxobjclass property of SelectedProviders. It could possibly be due to some escape characters & \n & \t characters present in the json object. This is still a valid json - I checked with an online json validator. But maybe Pega is not able to parse it due to these escape characters.
I have asked the backend team to check if they can eliminate these characters. But when u look at the page from the tracer it doesn't show these characters, but it does show up in SOAP UI. So ideally Parsing should also work correctly.