I have an email that can have multiple subject lines. This is based on the incoming data. For this, 1 content block is loaded containing all the different subject lines. The correct subject line is shown via a large IF ELSE statement.
Now some subject lines contain a variable. And to make it even more complex, this variable differs based on whether the field is filled or not. This is now working fine and looks like this:
%%[
set @klantnaam = AttributeValue('klantnaam')
set @bedrijfsnaam = AttributeValue('bedrijfsnaam')
IF @bedrijfsnaam != '' then
set @subjectKlant = concat('',@bedrijfsnaam,'')
ELSE
set @subjectKlant = concat('',@klantnaam,'')
ENDIF
]%%
%%[
if @identifier_moment == 'XXX' then
set @subjectline = concat('We hebben je pakket van ',@subjectKlant,' ontvangen')
elseif @identifier_moment == 'XXX' then
set @subjectline = concat('We hebben je pakket van ',@subjectKlant,' ontvangen')
etc..
else
set @subjectline = 'Volg je pakket'
endif
]%%
Now we have to make a change and the data for the subjectKlant variable is no longer available via a attribute field but is comming into a JSON. I build the following:
%%[
Set @adressen = [adressen]
]%%
{{.datasource adressenVar type=variable source=@adressen maxrows=1}}
{{.data}}
{"target":"@adressen"}
{{/data}}
%%[
var @subjectKlant
set @subjectKlant = TreatAsContent('{{bedrijfsnaam}}')
]%%
{{/datasource}}
And this is the JSON structure:
[{
"kind": "1",
"persoonsnaam": "Test1",
"bedrijfsnaam": "Test1 BV"
}, {
"kind": "2",
"persoonsnaam": "Test2",
"bedrijfsnaam": "Test2 BV"
}]
Basically this works. However, I face some difficulties that I can not solve at the moment. Hopefully some of you will know the answer. I have two questions:
- I have to check weither bedrijfsnaam is empty or not in the JSON. If not empty then show the content of that field, if the field IS empty then show the content of field persoonsnaam (like I build with AMPscript). How can I achieve this?
- How can I target a specific object within the JSON array? So suppose I want to target the fields that is under kind: 2?