Deserialize JSON Array to PageList with JSON Data Transform

So I have problem parsing JSON arrays which do not have named properties

I have a class Token

I have property PageList “tokens” of class Token on my Class XYZ

On my Class XYZ I have defined a JSON data transform to convert below JSON into “tokens” PageList

[ { “token1” : “value1” }, { “token2” : “value2” } ]

Token class has two properties “token” and value". The reason I have to do this is “token1” and “token2” are not fixed named property like “token” in which case I would have only 1 property in my Token class. I am forced to have two properties so I can extract raw data on the lhs and rhs

For life of me I cannot figure out how to do the mapping.

I specified Top Element Structure as an “Array” because top level object is an array and not object

Then I selected “Primary.tokens” for PageList property. It gives me error below



Cannot reference another top-level page: Primary.errors Invalid property reference

Needless to say I selected “Objects” for “Elements of this JSON are”

Since I cannot get past above basic errors I am not able to try anything else. Like, figuring out how to specify the JSON on the RHS when doing manual mapping because “token1” and “token2” are not fixed.

I am starting to think maybe I need to massage the JSON or maybe not use JSON data transform. Would really appreciate any pointers.

Hi @PEGAFREAK

With respect to the error mentioned, can you try removing the keyword Primary

Try with only the page list name in the JSON Data Transform.

JSON data transforms can only reference fields on the primary page.

@JayaL722 That is precisely the problem. It will not let me select my page list property unless I select “Primary” first and only then shows me the pagelist property property under it (in screenshot it says “errors” because I renamed “tokens” to “errors”). Hope I explained the issue now. Screenshots below

@PEGAFREAK

I was able to see the property in autocomplete and refer it.

Include a “.” and search for the property name

.

@JayaL722 Shoot! Okay yes. So now back to my real question. How do I parse random name value pairs in to multiple Error objects in my Errors Page List? As I stated earlier I will not know in advance the name is going to be “token1” or “token2” or whatever. Is there a logical way to refer to elements of each JSON object (i.e. { }). See screenshot below

Hi @PEGAFREAK

If you are aware of the possible list of keys(names) in JSON, you can define desired data model in Pega.

Then, Auto-map action will automatically map data from JSON to the clipboard.

@JayaL722 Okay so that is the issue. I do not know the “keys” in advance. In my original example I called the “token1”, “token2”, it could really be anything. Basically they are name value-pairs with both name and value only known at run time.

So either JSON data transform is not the right way and / or I need to see if there is some function availabl / or I have to write my own function.

Hi @PEGAFREAK

Yes, probably you would have to write custom function to convert the string to list of map and iterate the names and values.