1

I got a json object parsed from SSJS. This way

var payload = eval( "(" + myJson.Content + ")" );

And later I pass that payload to AMPSCRIPT

Variable.SetValue("@invoice", payload.invoice);

How can I access "city" property from @invoice? I only want to write it in my html.

I used: ROW and FIELD ampscript functions but It always gives me an error...

payload.invoice is this type: System.Collections.Generic.Dictionary`2[System.String,System.Object]

Any suggestion?

Thank you

1 Answer 1

2

I typically parse JSON in an email like this:

<script runat="server">

Platform.Load("Core","1.1.1");

var json = Attribute.GetValue('json');
var jsonObj = Platform.Function.ParseJSON(json);

if (jsonObj.length > 0) {

  for (var i = 0; i < jsonObj.length; i++ ) {

      var item = jsonObj[i];
      Platform.Variable.SetValue("@sku",item['sku']);
      Platform.Variable.SetValue("@name",item['name']);
      Platform.Variable.SetValue("@url",item['url']);

      </script>

      <br><a href="%%=redirectto(@url)=%%">%%=v(@sku)=%%</a> - <a href="%%=redirectto(@url)=%%">%%=v(@name)=%%</a>

      <script runat="server">
  }
} else {

  Write("no products found")

}
</script>
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .