I have a successful payload from my API call. Successful Return Payload:
{status:“success”, state:”QLD”, Code:”123”, offerName:”EOFY Deal”, offerDiscount:”30%”, offerStartDate:”2020-06-01” , offerEndDate:”2020-06-30”}

What's the best way to use this Json file as my dynamic content using AMPscript in emails. The offer only pertains to recipients who live in the state, and are linked to this code. Recipients are stored in their own DE.

I thought of moving the JSON file into a DE_Offer and link it to the Recipient table. Refresh the DE_offer on a daily basis, by calling the API but looks like that doesn't work.

What's the best way to call the offer data in Real Time and use it at the time of send for eligible recipients?


1 Answer 1


So I would not recommend JSON parsing via AMPScript. I would utilize Serve-Side JavaScript (SSJS) or Guide Template Language (GTL) to do this. I almost exclusively recommend SSJS as I feel it gives you more options and capabilities, but it also has a bit heavier overhead to learn and use.

Here is an example in SSJS:

<script runat=server>

var url = 'http://www.example.com'
var resp = HTTP.Get(url);
var status = resp.status;
var state = resp.state;

You can then either use the SSJS to AMPScript var functions or use the SSJS var outputs <ctrl:var name=status /> to push your vars into the email.

The other option is GTL:

%%[ SET @Json = '{status:"success", state:"QLD", Code:"123", offerName:"EOFY Deal", offerDiscount:"30%", offerStartDate:"2020-06-01" , offerEndDate:"2020-06-30"}' ]%%

{{.datasource JSONVar type=variable maxRows = 20}}
    { "target" : "@Json" }
     Status: {{status}}
     State: {{state}}
     Code: {{Code}}
     OfferName: {{offerName}}

Which would then output the vars from the JSON.

AMPScript does not natively have any way to parse through JSON, you would be forced to manually cut into it via RegEx and/or Substring, IndexOf, etc. Which can be dicey and usually requires a lot of upfront effort and caveats and business rules to ensure it functions as expected.

  • Thank you. This is great. One last question when I use GTL, I still need to separately make the API call and manually add the payload in the Set @Json variable for it to work?
    – Kim
    Nov 20, 2020 at 23:08
  • @Kim correct. You would make the call via AMPScript and use that var instead of the one I showed manually filled in Nov 20, 2020 at 23:15
  • Thank you much appreciated.
    – Kim
    Nov 21, 2020 at 22:39
  • @Kim - if this answered your question please mark it as accepted (checkmark next to the answer) so others can more easily find the solution if they face the same issue. Nov 23, 2020 at 14:22

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.