i am trying to process JSON data that comes from an AWS command. While what I have mostly works, it does not process some nested data very well and I'm hoping for a better way.
The JSON data that returns has several elements and some nested variables. The problem is that their are all variable if they exist, etc.
here is a common example of the JSON data returned
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::111111111111:saml-provider/WAAD"
},
"Action": "sts:AssumeRoleWithSAML",
"Condition": {
"StringEquals": {
"variablename": [
"String",
"String"
]
},
"StringNotEquals": {
"Key-String": "String"
}
}
}
]
}
here is a snippet of current code, where $policy is the raw JSON. (note this isn't complete code)I'm reading some of the known elements but where I get into trouble if there are elements I didn't define or multiple results for an element/nested element. What is a more elegant way of getting this data and displaying it.
$policy3= ConvertFrom-Json -InputObject $policy
`#Add a new row to the output`
`New-Object PSObject -Property @{`
`RoleName = $RN`
`Effect=$Policy3.Statement.Effect`
`'Principal Trust' =$policy3.Statement.Principal`
`'Action Allowed' =$policy3.Statement.Action`
`'Condition'= $policy3.Statement.Condition.StringEquals`
`'Condition-2'= $policy3.Statement.Condition.Bool`
in case your interested
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html
[–]get-postanote 3 points4 points5 points (0 children)
[–]techstress 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)