1

EDIT: It occurred to me that there is a much simpler, broader way of asking this (or at least very relevant to it): is there a way to pull unique values from a JSON attribute, e.g. within the .datasource filter functionality?

Original question:

I'm trying to figure out a way within Marketing Cloud's GTL scripting to conditionally determine the display of JSON content based on the presence of similar values later in the recordset. So the JSON might look like this:

[
{
"Items": [                   
    {
        "ItemNumber": 101,
        "ItemName": "Item A",
        "ItemTypeID": 12345,
        "ItemTypeDescription": "Don't look at it wrong."      
    },
    {
        "ItemNumber": 201,
        "ItemName": "Item B",
        "ItemTypeID": 12345,
        "ItemTypeDescription": "Don't look at it wrong." 
    },
    {
        "ItemNumber": 301,
        "ItemName": "Item C",
        "ItemTypeID": 98765,
        "ItemTypeDescription": "Mostly harmless." 
    }
    ]
}

]

So for the above, imagine that I want to list all of the ItemName, ItemTypeID, and ItemTypeDescription via GTL (easy enough), BUT I only want to display that ItemTypeDescription once if two items have the same ItemTypeID. So I'd need some way to check for duplicate instances in advance and only display the ItemTypeDescription on the last instance of that ItemTypeID. So the output would be something like:

Item Name - Item A | Type ID - 12345

Item Name - Item B | Type ID - 12345 | Type description: Don't look at it wrong.

Item Name - Item C | Type ID - 98765 | Type description: Mostly harmless.

In actual practice, I'd obviously want to format the presentation of Items A and B so they are better grouped visually, but I hope this at least gets the gist across.

I know how I'd pull this off in Ampscript if it had a JSON parsing function, but is this asking too much of GTL's capabilities?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.