1

I am trying to make a call to external API but I don't know how to correctly parse results. Here is the format of the response. I can correctly parse the Status, but Results is an array and nothing so far works:

{ 
   "Status":"OK",
   "Results":[ 
      { 
         "Header1":null,
         "Header2":null,
         "Header3":null
      }
   ]
}

Here is what I have tried and it doesn't work:

var res = HTTP.Get(url); <- up to here it works

var Response = Platform.Function.ParseJSON(res.Response[0]);

var Header1 = Platform.Function.ParseJSON(res.Response[0].Header1);  <- doesn't work
var Header1 = Platform.Function.ParseJSON(Response.Header1);  <- doesn't work
var Header1 = Platform.Function.ParseJSON(res.Header1);  <- doesn't work

And also this:

var res = HTTP.Get(url); <- up to here it works
var Response = Platform.Function.ParseJSON(res.Response[0]);
var Header1 = Response.Header1;  <- doesn't work
var Header1 = res.Response[0].Header1;  <- doesn't work

Can you please suggest the best way to get all three headers from the Response array. Thank you

3
  • var res = HTTP.Get(url); <- up to here it works ==> after this line, can you put console.log(res) and show what you are getting? Oct 21, 2019 at 8:34
  • 2
    In your example JSON you have a Results collection. In your code you reference Response as the collection name. Does Platform.Function.ParseJSON(res.Results[0].Header1) work? Oct 21, 2019 at 9:42
  • Thank you Richard that was it. What a stupid mistake. Thank you Oct 21, 2019 at 11:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.