I've been having a lot of success parsing JSON with GTL for emails, but there's something that I just cannot get to work.
Given the following JSON
{
"category1": "something",
"category2": "something else",
"people": [
"Yehuda Katz",
"Alan Johnson",
"Charles Jolley"
]
}
I want to be able to iterate through the list of people. My sample code looks something like:
%%[ var @Json set @Json = '{"category1":"something","category2":"something else","people": ["Yehuda Katz","Alan Johnson","Charles Jolley"]}' ]%%
{{.datasource JSONVar type=variable maxRows = 20}}
{{.data}}
{ "target" : "@Json" }
{{/data}}
{{.datasource JSONpeople type=nested maxRows = 10}}
{{.data}}
{ "target" : "JsonVar.people" }
{{/data}}
Json People is: ????????
{{/datasource}}
{{/datasource}}
Currently I just cannot find any code that will display those names.
In particular, I've played around with the {{#each}} tag (https://developer.salesforce.com/docs/atlas.en-us.mc-programmatic-content.meta/mc-programmatic-content/gtlEach.htm) and it works when I have something to key off like in:
{{#each JsonVar}}
{{SomeValue}}
{{/each}}
That won't work, because there isn't a value to put in the loop.
The docs reference using either
{{.this}}
or
{{this}}
or
{{.}}
But none work. At best it will literally say {{.this}} and not treat it as a variable, but whenever I use {{.}} it completely blows up the email rendering with the error:
"There is an error in your email. Please contact your customer service representative. Error 1: Error Loading Email Content
An error occurred when attempting to parse HtmlEmailBody content for HTML content. MemberID: 111111 JobID: 0 ListID: 48 Content Begins With: Invalid Content:
..."
I also do not have the ability to change the incoming JSON, and its frustrating because the docs definitely indicate this is possible. Anyone have any thoughts?