Can AMPScript parse JSON?

Using AMPScript to parse an XML feed. Client is switching to JSON. Is there something similar to BuildrowsetfromXML() for JSON in AMPScript? I am confined to using the members login area and not an external API application.

Answer

I did this using SSJS and eval(). I could not find a way to parse JSON in AMPscript. Also if I recall correctly JSON.parse() is not implemented in ExactTarget.

There are security concerns with eval() so you should only use it with a trusted source.

Here is my example, where I first use HttpGET() in AMPscript to retrieve JSON from my trusted source.

%%[ set @JSON = HttpGET("http://some-url-that-returns-json") ]%% 

<script runat="server">
    Platform.Load("Core", "1")
    // get JSON from ampscript
    var jsonObj = Variable.GetValue("@JSON");
    var evaluatedJSON = eval("(" + jsonObj + ")");
</script>

Attribution
Source : Link , Question Author : xtianjs , Answer Author : Jon Sakas

Leave a Comment