Test User
Test User

Reputation: 1

Unable to iterate json array in for each loop using velocity template

I have a json like this :

{
"name" : "xyz",
"age" : "12",
"familyprofile" : 
[{"name" :"abc", "Occupation":"manager","age":"30" },{"name" :"def","Occupation":"housewife","age":"30"}]
}

i am trying to print family profiles in table using velocity template.

<table>
<tr>
<td><b>name</b></td>
<td><b>Occupation</b></td>
<td><b>age</b></td>
</tr>
#set($steps = {$headers.familyprofile})
#foreach($step in $steps)
<tr>
<td>step.name</td>
<td>step.Occupation</td>
<td>step.age</td>
</tr>
#end
</table>

Upvotes: 0

Views: 595

Answers (1)

Claude Brisson
Claude Brisson

Reputation: 4130

It's a syntax problem, you should use:

#set($steps = $headers.familyprofile)

or:

#set($steps = ${headers.familyprofile})

Upvotes: 0

Related Questions