Returning a loop index
Use a LoopIndex function to return the index for a loop and its parent.
Before you begin
About this task
In this example, you have a JSON file containing information about team
managers and employees. You want to create an XML file with employee information, including
a unique employee index and a team index. You can use the following JSON sample as input:
{
"team":[
{
"manager":"Steve Rogers",
"employees":[
"Tony Stark",
"Natasha Romanoff",
"Bruce Banner",
"Clint Barton"
]
},
{
"manager":"Reed Richards",
"employees":[
"Susan Storm",
"Johnny Storm",
"Ben Grimm"
]
}
]
}
You can use the following XML sample to create your output
structure.
<root>
<employee>
<employeeName/>
<employeeIndex/>
<teamIndex/>
</employee>
<employee>
<employeeName/>
<employeeIndex/>
<teamIndex/>
</employee>
</root>
Procedure
Results
<root>
<employee>
<employeeName>Tony Stark</employeeName>
<employeeIndex>1</employeeIndex>
<teamIndex>1</teamIndex>
</employee>
<employee>
<employeeName>Natasha Romanoff</employeeName>
<employeeIndex>2</employeeIndex>
<teamIndex>1</teamIndex>
</employee>
<employee>
<employeeName>Bruce Banner</employeeName>
<employeeIndex>3</employeeIndex>
<teamIndex>1</teamIndex>
</employee>
<employee>
<employeeName>Clint Barton</employeeName>
<employeeIndex>4</employeeIndex>
<teamIndex>1</teamIndex>
</employee>
<employee>
<employeeName>Susan Storm</employeeName>
<employeeIndex>5</employeeIndex>
<teamIndex>2</teamIndex>
</employee>
<employee>
<employeeName>Johnny Storm</employeeName>
<employeeIndex>6</employeeIndex>
<teamIndex>2</teamIndex>
</employee>
<employee>
<employeeName>Ben Grimm</employeeName>
<employeeIndex>7</employeeIndex>
<teamIndex>2</teamIndex>
</employee>
</root>