Understanding GTL Limitations
GTL is a templating language used in Salesforce Marketing Cloud to parse and transform data from various sources, including JSON. However, as noted in the community discussion, GTL has limitations when it comes to parsing JSON arrays of strings.
For example, given a JSON array like this: “FormattedAddress”:[“WESTON20PKWY”,”CARY NC 27513″,”UNITED STATES”], GTL is unable to parse it directly.
Root Cause
GTL is designed to work with JSON objects that have key-value pairs, and it does not support parsing JSON arrays of strings directly.
This limitation is not unique to GTL, as other templating languages like Handlebars also have similar limitations.
Workaround
To parse a JSON array of strings, an alternative approach is needed. One possible solution is to use a script to transform the JSON array into a compatible format that GTL can parse.
transform.js
var jsonData = {"FormattedAddress":["WESTON20PKWY","CARY NC 27513","UNITED STATES"]};
var transformedData = {};
transformedData.FormattedAddress = jsonData.FormattedAddress.map(function(address) {
return { address: address };
});
This script transforms the JSON array into an object with a key-value pair, where the value is an array of objects with a single property called “address”.
Conclusion
In conclusion, while GTL has limitations when it comes to parsing JSON arrays of strings, there are alternative approaches that can be used to transform the data into a compatible format.
Checklist for Parsing JSON Arrays with GTL
- Check if the JSON array has key-value pairs, if so, use the standard GTL syntax to parse it.
- If the JSON array is an array of strings, use a script to transform it into a compatible format.
- Use the transformed data to populate the GTL template.
- Test the GTL template to ensure it is working as expected.
- Consider using alternative templating languages or approaches if GTL is not suitable for the use case.
What is GTL?
GTL is a templating language used in Salesforce Marketing Cloud to parse and transform data from various sources, including JSON.
Can GTL parse JSON arrays of strings?
No, GTL is unable to parse JSON arrays of strings directly.
What is the alternative approach to parse JSON arrays of strings?
Use a script to transform the JSON array into a compatible format that GTL can parse.
Can I use Handlebars to parse JSON arrays of strings?
No, Handlebars also has limitations when it comes to parsing JSON arrays of strings.
Need help shipping this in production?
Genetrix builds and untangles Salesforce Marketing Cloud and Agentforce setups for teams that want it done right the first time. If anything in this post sounds familiar, talk to us before it ships.