Expand my Community achievements bar.

Join expert-led sessions on Real-Time CDP & Journey Optimizer designed to boost your impact.
SOLVED

Parsing the product string using Data Prep

Avatar

Level 2

We are use the Adobe Bridge SDK to bring mobile data into AEP. With that we are using the data prep tool to extract context variables and assign them to schema locations. We have come to a snag with the product string. We want to map this to the productListItems array (the default location for the product string).

 

We thought of creating a calculated field and using the  analytics functions, e.g. aa_get_product_names

https://experienceleague.adobe.com/en/docs/experience-platform/data-prep/functions#analytics

This outputs an array of values and we would then assign this to a schema path within productListItems.

The issue we have run into is that these analytics functions always output an array of strings - ["34","4","57] and we need in some instances floats or integers. We cannot use the to_integer/float functions as these only work on 1 string at a time and not arrays. We also cannot reference the entire array using [*] - as this is not supported.

 

Has anyone run across this issue and been able to solve it?  I cannot believe we are the only ones using bridge sdk and having a product string.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi @timytim75 ,

Have you tried below?

json_to_object(
  concat(
    "[",
    join(",", aa_get_product_ids(productString)),
    "]"
  )
)

I am expecting above can give you output like [34, 4, 57]

Reference:
https://experienceleague.adobe.com/en/docs/experience-platform/data-prep/functions

Note: This response is partially inspired from Generative AI.

Thanks

Ankit

View solution in original post

5 Replies

Avatar

Correct answer by
Level 7

Hi @timytim75 ,

Have you tried below?

json_to_object(
  concat(
    "[",
    join(",", aa_get_product_ids(productString)),
    "]"
  )
)

I am expecting above can give you output like [34, 4, 57]

Reference:
https://experienceleague.adobe.com/en/docs/experience-platform/data-prep/functions

Note: This response is partially inspired from Generative AI.

Thanks

Ankit

Avatar

Level 2

This did it. I just removed the concat and [] (didn't need them).

 

Thanks!  I should pay you the $250 per hour instead of these Adobe consultants

Avatar

Level 7

Glad to know that it worked for you!

 

Thanks

Avatar

Level 4

In general capabilities for nested parsing in Data Prep are relatively simplistic, likely due to the fact that it will be affecting data ingestion time and load if they are too complicated. You can do a single level of parsing, as you have, but to get each output and then parse each property for each row or anything similar will not work. Now for products the issue is more complex than that, since you can extract you product names, quantities, prices and whatnot individually, but to join multiple arrays into an array of objects, so that a each array represents a specific property for the object? As I'm aware this is not possible, since you cannot use any variables, wildcards, loops or anything complicated in the rules.


I have used edge bridge once, but unfortunately we didn't touch the products-string at that time. I looked at some related materials, but there doesn't seem to be any, even though there are mentions of data mappings:

Straight up I don't see a way to do this with Data Prep, but I could be wrong. Having a specific function for this purpose would be ideal, but seeing as how much complexity the products-variable may have (merchandising evars and events), this may be rather difficult to do.

 

How would I solve this is to do the mapping in the app and pass the readily formatted XDM value e.g. in context data as an array of objects, and then map that directly to productListItems in Data Prep. Disclaimer that I haven't tried this, but it might work.


I would love to hear of a solution if you figure this out, as this is very similar to multiple times I wanted to solve things with Data Prep, only to realize that it cannot be done when nested data (e.g. array of objects) is in question.

Avatar

Level 10

Hi @timytim75 ,

 

You're encountering a common challenge when working with AEP Data Prep and the Adobe Bridge SDK's product string. The aa_get_product_names function, while convenient for extracting product names, inherently returns an array of strings, even if the underlying data represents numbers (integers or floats). The lack of direct array manipulation with to_integer or to_float makes direct conversion difficult.

 

The most efficient and robust solution is to perform the type conversion within your Bridge SDK implementation, if possible. Before constructing the productListItems array within your Bridge SDK code, convert the numeric product strings to their appropriate numeric types (integers or floats). This is the cleanest and most efficient solution. Your code would look something like this:

    

List<Object> productList = new ArrayList<>();

String[] productStrings = getProductStrings(); // Your existing method to get product strings

 

for (String productString : productStrings) {

    try {

        int productInt = Integer.parseInt(productString);

        productList.add(productInt);

    } catch (NumberFormatException e) {

        try {

            float productFloat = Float.parseFloat(productString);

            productList.add(productFloat);

        } catch (NumberFormatException e2) {

            // Handle cases where the string is neither int nor float (e.g., add as string)

            productList.add(productString);

        }

    }

}

 

Now send the 'productList' to AEP:

sendProductListToAEP(productList);

 

Thanks,

Jyoti