I am trying to get the list of "enabled" features from featureset array from below JSON snippet with powershell. output expected :
feature1, feature2, feature4
I tried this piece of code but I was only able to get to the specific index of the array, not all elements, also not able to put condition for "enable" = true :
$output = foreach( $feature in $jsn.abc.comp1.featureset[0].psobject.Properties ) {
[PSCustomObject]@{
featureName = $feature.Name
featureValue = $feature.Value
}
}
json:
{
"abc": {
"comp1": {
"id": "1308",
"featureset":[
{
"name": "feature1",
"enable" : true,
"ID": "0670FF495355878281174937"
},
{
"name": "feature2",
"enable" : true,
"ID": "0670FF495355878281174937"
},
{
"name": "feature3",
"enable" : false,
"ID": "0670FF495355878281174937"
},
{
"name": "feature4",
"enable" : true,
"ID": "0670FF495355878281174937"
}
]
}
}
}
$json.abc.comp1.featureset | ? enablenamekey and its value can be retrieved for enabled features ?$json.abc.comp1.featureset | ? enable | % namewould also work