I have checked with foreach and foreach-object but unable to iterate any value out of it even using convertFrom-json, so I’m liitle bit clueless on this part – any idea how to iterate though every cell of it ?
I have tried with the below but it didn’t work out
foreach ($sublist in $data) { foreach ($item in $sublist){ Write-Host
("the value is :"+$item) } }
[
[
[
"test-1234",
"2023-07-11T04:00:24+00:00"
]
],
[
[
"sb-00091",
"2023-07-11T04:00:21+00:00"
]
]
]
I would like to iterate through and would like to get the corresponding value of Timestamp i.e. for test-1234 it is 2023-07-11T04:00:24+00:00 , then how should I need to update the loop
a b
test-1234 2023-07-11T04:00:24+00:00
sb-00091 2023-07-11T04:00:21+00:00
Is there any book or online article available if I can go through it
2
Answers
Use the suggested solution from your previous question to extract a flat list of values, then create a new object from each pair:
This approach might not work if the data isn’t uniform (eg. if the second value in the inner array might not be a string), but you could modify the previous solution to test for whether a given collection has a count of two and a string in the first slot:
Similar approach to Mathias’s last example but incrementing an index that is coerced into a
char
later (65
would beA
). Downside is that if arrays don’t have uniform counts you would end up with not normalized objects or objects not having uniform properties.Output should look like: