cancel
Showing results for 
Search instead for 
Did you mean: 

Freemarker loop through JSON object

mikepoole
Champ in-the-making
Champ in-the-making
I have a webscript that is as follows:
var jsonRes = remote.call("/employeelist");
var result = eval('(' + jsonRes + ')');
model.employeelist = result;

This webscript returns a JSON object as shown in the example below

Example:

{ "employees": [
{ "name": "Fred Bloggs", "email": "fred@test.com", "id": "123456" } ,
{ "name": "John Smith", "email": "john@test.com", "id": "456789" } ,
{ "name": "Bob Brown", "email": "bob@test.com", "id": "987654" }  ] }

How can my Freemarker code loop through so that I can display the following…

Fred Bloggs : fred@test.com
John Smith : john@test.com
Bob Brown : bob@test.com

When I use

<#list journallist?keys as prop>
${prop}
</#list>

it returns

"employees"


Many thanks

Mike
2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator
Try this

First change in js

last line
model.employeelist = results["employees"];

then in ftl
<#list employeelist as emp>
${emp.name}
</#list>

Hi,

I have issue with Json array object for iterating element from FTL file. see below json formt.



{"empObjects":[[120,"Chandra","Reddy"],[121,"Eswar","Reddy"]]}

Thanks,
Chandra