Expand my Community achievements bar.

Join us for an upcoming in-person Adobe Target Skill Builders event ~~> We're hosting these live learning opportunities to equip you with the knowledge and skills to leverage Target successfully. Learn more to see if we'll be coming to a city near you!

Working with Json Arrays in a Profile Script


Level 2

I am starting with Adobe Target and I would like to understand some weird things I see playing with the profile scripts.

I am creating and storing a simple list of objects containing. the objects contains just two attributes: one is an string and the other one is an integer.

When I try to get this back from the user parameter the first thing that I see is that the Json is not in a Json format anymore as it changes the ":" with "=", the other thing I see is that the integers has been converted into float.

An example of this would be:

Before storing the parameter: [ { "stringItem" : "item1", "intItem" : 12 },   "stringItem" : "item2", "intItem" : 24 }]

When I get the stored parameter: [ { "stringItem" = "item1", "intItem" = 12.0 },   "stringItem" = "item2", "intItem" = 24.0 }]

And after this I cannot longer work with the attibutes inside, actually I can't event do simple things as trying to get the type of that array element typeof(array[0])

Is there anyone that can explain me how to work with objects stored inside user parameters?



1 Reply


Level 1

I solved this by storing the entire object as a string and parsing it when fetching. There appears to be issues whenever you look inside and array or object that has been stored as is as a profile attribute, it silently fails and there is no debugging to find out what's going on. But if you store it as a string and convert back and forth it all seems to behave as expected.
So mine looked like:

var getData = user.get('scriptName');

var parseData = JSON.parse(getData);

//do stuff to parseData

var storeData = JSON.stringify(parseData);

return storeData;