Here's an example blob of JSON:
{
"inventory": {
"trucks": {
"wheels": {
"count": 4,
"brand": "fireyear"
},
"engine": {
"valveCount": 3
}
},
"planets": {
"ringed": [
"saturn"
],
"questionable status": [
"pluto"
]
}
}
}
I want to write a powershell function that takes a node as an argument, and determines if it's object-like or not. If it isn't, it does something with the value. Otherwise, it calls itself recursively with each value.
Something like this workflow:
PS> $x=(Get-Content -Path big-blob-of-json.json | ConvertFrom-Json)
PS> f("", $x)
where the empty-string in the call to the json-processing-function indicates that we're at the root.
All the docs I've looked at so far show how to convert a hashobject into a PSCustomObject
, but from what I can tell those work with known keys. In my case the keys are completely arbitrary and unknown in advance, but are of interest.