I have a JSON like this,
{
"TotalCount": 2,
"Data": [
{
"ID": 9663696221792,
"Code": "08099991",
"Items": [
{
"Amount": 5.05,
"LineNo": 1
},
{
"Amount": 16.08,
"LineNo": 2
}
]
},
{
"ID": 9663696221793,
"Code": "08028001",
"Items": [
{
"Amount": 26.13,
"LineNo": 1
}
]
}
]
}
And I need the output to be like this,
| row | ID | CODE | Cost |
|---|---|---|---|
| header | 9663696221792 | 08099991 | 21.13 |
| Item 1 | 9663696221792 | 08099991 | 5.05 |
| Item 2 | 9663696221792 | 08099991 | 16.08 |
and
| row | ID | CODE | Cost |
|---|---|---|---|
| Header | 9663696221793 | 08028001 | 26.13 |
| Item 1 | 9663696221793 | 08028001 | 26.13 |
and so on for more headers and items
so far
$array = Get-Content -Path 'response.json' | ConvertFrom-Json
then I cycle through
foreach ($root in $array.data)
then though each item
foreach ($Item in $array.data.items)
however this cycles through all Items in the data array.
any ideas.
foreach ($Item in $root)or maybeforeach ($Item in $root.Items)?