I have my json as follows
{
"cluster": [
{
"id": "cluster1.1",
"color": "blue",
"segment": [
{
"id": "segment1.1",
"color": "green"
}
]
},
{
"id": "cluster1.2",
"color": [
"blue",
"red"
],
"segment": [
{
"id": "segment1.2",
"color": "Yellow"
}
]
},
{
"id": "cluster1.3",
"color": "Orange",
"segment": [
{
"id": "cluster1.3",
"color": "black"
},
{
"id": "cluster1.4",
"color": "Green"
},
{
"id": "cluster1.5",
"color": "red"
}
]
},
{
"id": "cluster1.4",
"color": [
"blue",
"red"
],
"segment": [
{
"id": "cluster1.4",
"color": "red"
},
{
"id": "cluster1.5",
"color": "blue"
},
{
"id": "cluster1.6",
"color": "Yellow"
}
]
}
]
}
I would like to loop this recursively through all nodes, I am getting the content as follows with the following code but I am not getting through all the nodes
$jsonData = (Get-Content -FilePath) -join "`n" | ConvertFrom-Json
for( $i=0; $i -lt $jsonData.cluster.Length; $i++)
{
$clusterInfo= $ReportingPackage.cluster[$i]
$clusterInfo.Color
}
I need to recursively find a way to loop through all segments and colors