1

I have a SSJS code that i am running SFMC cloudpages. The code is to do a HTTP.GET call to a url and then parse the JSON response.when trying to write out the result of parse i receive the following error message:

System.Collections.Generic.Dictionary`2[System.String,System.Object]

when i try to write out the variable "resultString" i get the JSON response exactly as it should be. but when i try to write out the variable json_el ( the supposed parsed string ) i get the error. I also tried writing out the key values in the JSON object such as Write(json_el.SchoolList[0].SchoolName); and the error does not occur but it produces blank or just nothing. i tried replacing String() function with Stringify() but results were either blank or the same error. I have looked at other questions in the community and still can't seem to figure out what the problem is. please help me as this is urgent and i am pretty much stuck on something that should be working.

<script language="javascript" runat="server">

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

var newsletterDE = DataExtension.Init("utility_subs_geo_appended");
var newsletterRows = newsletterDE.Rows.Retrieve();

  
// Make REST API call and get JSON response
var url_el = ('https://api.schooldigger.com/v2.0/schools?st=GA&level=Elementary&isVirtual=false&nearLatitude=33.171511&nearLongitude=-84.904805 &distanceMiles=15&page=1&perPage=1&sortBy=rank&includeUnrankedSchoolsInRankSort=false&appID=eed66488&appKey=9e64916a9410250d80f9740479c4512e');
var response_el = HTTP.Get(url_el);
var resultString = String(response_el.Content);
var json_el = Platform.Function.ParseJSON(resultString);

Write(json_el);

</script>
1
  • What exact attributes do you want to get from the response? Commented Oct 28, 2023 at 1:06

1 Answer 1

2

You are not getting an error, but rather you're writing out exactly what you've asked for. Your json_el variable contains a C# Dictionary Object and you're told that the variable contains an object. If you want to see the key value pairs stored in the Dictionary Object, Stringify it before printing:

    Write(Stringify(json_el));

JavaScript is case sensitive, so if you want to inspect your json_el object, you'll need to pay attention to the casing of attribute names. The names of both your "schoolList" array and the "schoolName" property start with a lowercase "s", not uppercase, so to print out the name of the first school in your array, you'd need to do it, so...

    Write(json_el.schoolList[0].schoolName);

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.