Gursimrat
11 years agoLeader
Iterate through JSON response in FTL
Hi,
I am getting a response in my endpoint via http.client.request in the JSON format, I want to iterate thorugh the nodes of the json via FTL, but I am not able to.
Code to read the json:
<#assign search_query = http.request.parameters.name.get("search_query","test") /> <#assign response = http.client.request("http://external-search/collection1/select?q=${search_query}&wt=json&indent=true").get() /> <#if response.hasError> ${response.error.message} <#else> <#assign response2 = response.content.docs> <#list response2 as result>
${result.summary}
</#list> </#if>
The JSON is as below:
{ "response":{ "start":0, "docs":[ { "summary":" results community ", "body":"Array results community Re: results community Re: results community", "votecount":0, "_version_":1463544135618134016, "noOfComments":2, "lastmodified":"2014-03-08T06:06:07+00:00", "type":"board", "url":"/threads/id/149", "id":"149", "title":"results community", "postedby":"Varun", "sectionlabel":"Using results", "sectionid":"using-results" }, { "summary":" New threads in the results communityNew threads in the results community ", "body":"Array New Message Re: New Message", "votecount":0, "_version_":1463544135667417088, "noOfComments":1, "lastmodified":"2014-02-25T18:42:46+00:00", "type":"board", "url":"/threads/id/83", "id":"83", "title":"New Message", "postedby":"Varun", "sectionlabel":"Testing Stories", "sectionid":"testing-stories" } ], "numFound":42 }, "responseHeader":{ "status":0, "QTime":1, "params":{ "indent":"true", "q":"results", "wt":"json" } } }
Giving error:
{ "error":" FreeMarker template error: For "." left-hand operand: Expected a hash, but this evaluated to a string (wrapper: f.t.SimpleScalar): ==> response.content [in template "zendesksearchapiurl.ftl" at line 8, column 22] The failing instruction (FTL stack trace): ---------- ==> #assign response2 = response.content... [in template "zendesksearchapiurl.ftl" at line 8, column 1] #else [in template "zendesksearchapiurl.ftl" at line 6, column 1]