I've got some nested Json that's using a dictionary with dynamic keys and values - I don't know which key-value pairs will appear in the payload but I need to print them all in an email message.
The FOR IN loop in SSJS will handle this perfectly and my code below works (when I'm hard-coding in the array I need), but I need to dynamically pull in this nested 'MessageData' array that's being stored in my data extension and I'm unsure on how to do this.
<script runat="server">
Platform.Load("core","1");
var MessageData = {"UserId":12345678,"FirstName":"Example","Event":"SampleEvent"};
for (i in MessageData) {
Write('' +i+ ' = ' +MessageData[i]+ '<br>');
}
</script>
//output
UserId = 12345678
FirstName = Example
Event = SampleEvent
My payload looks like this (this is stored in a Data Extension field with no character limit and is populated via Transactional Messaging API):
{"FirstName":"Joe","EventDescription":"Great Holiday","FaultDateUTC":"2023-03-09T00:00:00.000Z","MessageData":{"UserId":12345678,"FirstName":"Example","Event":"SampleEvent"}}
How do I best target just the MessageData section to use it in my SSJS code? I have previously been using Guide Template language successfully but trying to do a for in loop in GTL doesn't appear straightforward.