1

we have a json object in a data extension. I would like to populate subject line depending on a field in that json.

How can I assign an ampscript variable a value from the json?

I tried this but that doesn't work:

%%[
var @Json 
set @Json = [order] 
]%%
{{.dataobject JsonVar type=variable source=@Json maxrows=1}}
{{.data}} 
{"target":"@Json"} 
{{/data}}

%%[
var @order_status
set @order_status = {{orderStatus}}
]%%
{{/dataobject}}
2

There are a couple of issues here.

Firstly, I would use datasource rather than dataobject as dataobject defines a global scope and while it makes the data available for reuse multiple times, the tags will need to be contained in section tags.

Secondly, you need to use the TreatAsContent() AMPscript function.

This should work:

%%[
var @Json 
set @Json = [order]
]%%

{{.datasource JsonVar type=variable source=@Json maxrows=1}}
{{.data}} 
{"target":"@Json"} 
{{/data}}

%%[
var @order_status
set @order_status = TreatAsContent('{{orderStatus}}')
]%%
{{/datasource}}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.