Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Converting a JSON file into an object, then how loop through to see what the data is?

$
0
0

 

 

PS C:\Users\epcsadmin\Desktop> cat .\data.json

{"status":"UP","diskSpace":{"status":"UP","free":99537080320,"threshold":10485760},"rabbit":{"status":"UP","version":"3.5.3"},"db":{"status":"DOWN","database":"Microsoft SQL Server","hello":

1},"configServer":{"status":"UP","propertySources":[]}}

PS C:\Users\epcsadmin\Desktop> $X = gc .\data.json| ConvertFrom-Json

PS C:\Users\epcsadmin\Desktop> $X

status       : UP

diskSpace    : @{status=UP; free=99537080320; threshold=10485760}

rabbit       : @{status=UP; version=3.5.3}

db           : @{status=DOWN; database=Microsoft SQL Server; hello=1}

configServer : @{status=UP; propertySources=System.Object[]}

 

SO i got this nice shiny object $X now. How do I loop through it to get the keys and values, like I would a hash table? The part (status, diskSpace, rabbit, db and configServer are variable from host to host I run this on. Bottom line I want to know which ones have a status=DOWN  in them


Viewing all articles
Browse latest Browse all 6937

Trending Articles