I'm trying to write some code in PowerShell v5.1 that recurses through a parsed JSON object to get its property names. An example JSON object is below:
{
"str1": "Hello World!",
"strings": {
"strA": "Foo!",
"strB": "Bar!"
},
"others": {
"myBool": true,
"myInt": 42
}
}
First I read and parse the object into a PSObject
:
$jsonString = '{"str1": "Hello World!", "strings":{"strA": "Foo!","strB": "Bar!"}, "others":{"myBool": true,"myInt": 42}}'
$json = $jsonString | ConvertFrom-Json
Next I can use $json.PSobject.properties.name
to get a list of all the top-level property names:
PS> $json.PSobject.properties.name str1 strings others
However, if I use $json.PSobject.properties.value
, I only see the first two values output:
PS> $json.PSobject.properties.value Hello World! strA strB ---- ---- Foo! Bar!
I would expect to see the others
property included here too. Is there a reason I'm not seeing it?