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

545 views Asked by At

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>
1

There are 1 answers

2
Claude Brisson On

It's a syntax problem, you should use:

#set($steps = $headers.familyprofile)

or:

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