I'm trying to use Calculated Fields in Data Mapping to transform objects in an input array that look like [{"key1":"string1","key2:"string2"},{"key1":"string1","key2:"string2"}] to an output array of objects that look like [{"value":"string1=string2"},{"value":"string1=string2"}], but I can't figure out the format needed for the input Source Fields, the combination of calculated fields needed, or the format needed for the output Target Field.
The objects in the array are always a pair of key:string, but the array is a dynamic size, sometimes containing dozens of {"key1":"string1","key2:"string2"} objects, so it's not feasible to individually reference the fields in each object in the input array entry via [0], [1], [2], etc. I tried using data.page.facetRefinement[*].name but the Calculated Field tool won't accept it.
Example input JSON:
{
"data": {
"page": {
"facetRefinement": [
{
"name": "Document Type",
"value": "PDF"
},
{
"name": "Category",
"value": "Important Stuff"
}
]
},
"eventInfo": {
"component": [
{
"type": "Image",
"name": "Hero"
}, {
"type": "List",
"name": "What's new!"
}, {
"type": "Carousel",
"name": "Featured Things"
}
]
}
}
}
Desired output (note: desired output format corrected based on @kautuk_sahni's reply):
{
"_experience": {
"analytics": {
"customDimensions": {
"lists": {
"list1": [
{"value": "Document Type=PDF"},
{"value": "Category=Important Stuff"}
],
"list2": [
{"value": "Image=Hero"},
{"value": "List=What's new!"},
{"value": "Carousel=Featured Things"}
]
}
}
}
}
}
Anyone have any ideas?
Thanks!
-Phil
Views
Replies
Total Likes
Hi @philschmidt
I saw you asked exactly the same question here, without answer yet. Can you give a quick update on what you have tried so far?
let's take one step back and check your output format. Pretty sure your array shall not contain one object with two "value" attributes.
"list1": [
{
"value": "Document Type=PDF",
"value": "Category=Important Stuff"
}
],
https://experienceleague.adobe.com/en/docs/analytics/implementation/vars/page-vars/list
lists are arrays of individual objects in your array instead
"list1": {
"list": [
{
"value": "Example value 1"
},
{
"value": "Example value 2"
},
{
"value": "Example value 3"
}
]
}
The inline documentation in the UX is really not helpful and is missing out explaining half of the function parameters. Not really surprised, Adobe...
After looking at the documentation, things seem to get more clear.
So, my best best would be to generate the whole array
to_array(true, to_object("value", concat(data.page.facetRefinement[*].name, "=", data.page.facetRefinement[*].value)))
to_array(true, to_object("value", concat(data.eventInfo.component[*].type, "=", data.eventInfo.component[*].name)))
and map it
_experience.analytics.customDimensions.lists.list1.list[*]
BUT: the UX validation/preview fails if asterisks are used
Alternatively, do try without the asterisks and see what the AEP Debugger logs show for mapping events.
The preview shows only a single item from the array though. So, no idea whether this is an error in the UX or if it by design only takes one item if no index is defined.
add_to_array([], to_object("value", concat(data.page.facetRefinement.name, "=", data.page.facetRefinement.value)))
add_to_array([], to_object("value", concat(data.eventInfo.component.type, "=", data.eventInfo.component.name)))
and map them to your list.
_experience.analytics.customDimensions.lists.list1.list
Thank you for your reply!
@bjoern__koth wrote:I saw you asked exactly the same question here, without answer yet. Can you give a quick update on what you have tried so far?
That was someone else's question that I commented on. @jinx0011's question was similar, but it was not exactly the same question. The main reason I asked this question separate from @jinx0011's question is because I did not want to presume the solution required the "Ability to use array notation ([*]) in calculated field". I also wanted to provide a set of input and output JSON examples so if people wanted they could paste the JSON into Data Mapping to define the incoming data and test/validate potential solutions.
Here's everything I that I tried (among calculated fields that Data Mapping allowed me to save without throwing an error), and their results:
============= First attempt =============
=== Result (from analytics.hit in AEP Assurance session) ===
mvvar2: [Ljava.lang.Object;@7f24998d|[Ljava.lang.Object;@27082dd5=[Ljava.lang.Object;@5458d032
============= Next attempt =============
=== Result (from analytics.hit in AEP Assurance session) ===
mvvar1: [Ljava.lang.Object;@50fc0814
mvvar2: [Ljava.lang.Object;@e0fa70e
============= Next attempt =============
=== Result (from analytics.hit in AEP Assurance session) ===
mvvar1: [Ljava.lang.Object;@5239757d=[Ljava.lang.Object;@269e0fc1
mvvar2: |[Ljava.lang.Object;@6025240f=[Ljava.lang.Object;@71bd3c1b
============= Next attempt =============
=== Result (from analytics.hit in AEP Assurance session) ===
mvvar1: [Ljava.lang.Object;@13d8bcfc=[Ljava.lang.Object;@4ecf0391
mvvar2: [Ljava.lang.Object;@72fc2d9c=[Ljava.lang.Object;@76fc9f7a
============= Next attempt =============
=== Result (from analytics.hit in AEP Assurance session) ===
mvvar1: [Ljava.lang.Object;@a293444=[Ljava.lang.Object;@48a494bd
mvvar2: [Ljava.lang.Object;@60ffb376=[Ljava.lang.Object;@3da1a04d
============= Next attempt =============
=== Result (from analytics.hit in AEP Assurance session) ===
mvvar1: BLANK
mvvar2: [Ljava.lang.Object;@db02553=[Ljava.lang.Object;@7265197f
============= Next attempt =============
=== Result (from analytics.hit in AEP Assurance session) ===
mvvar1: BLANK
mvvar2: [Ljava.lang.Object;@6d1bccea=[Ljava.lang.Object;@74360ab3
============= Next attempt =============
=== Result (from analytics.hit in AEP Assurance session) ===
mvvar1: [Ljava.lang.Object;@6a54ae68=[Ljava.lang.Object;@2da93725
mvvar2: [Ljava.lang.Object;@61d7f137
So, none of these worked (obviously). Also, when I tried to use wildcards in Calculated Fields (e.g. data.eventInfo.component[*].type) , when I tried (unsuccessfully) to save the changes I got an "parsing error in '['." error. Example:
There was an expression parsing error. The expression add_to_array(to_array(true,to_object("","")), to_object("value", concat(data.eventInfo.component[*].type, "=", data.eventInfo.component[*].name))) failed to parse com.adobe.aep.aexl.jexl.AexlScriptEngine$AepJexlEngine.parse:113@1:97 parsing error in '['.
Views
Replies
Total Likes
@philschmidt Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
No, I don't have a solution yet.
-Phil
Views
Replies
Total Likes
Views
Likes
Replies
Views
Like
Replies
Views
Like
Replies