I have a really weird json file and I am trying to extract data from it via powershell.
The issue is that the creator of this file is using json in a way I have never seen before:
(Cities are not in the Array, Continents are not in the array etc)
Shortened JSON File:
{
"zscloud.net": {
"continent : EMEA": {
"city : Abu Dhabi I": [
{
"range": "147.161.174.0/23",
"vpn": "",
"gre": "",
"hostname": "",
"latitude": "24.453884",
"longitude": "54.3773438"
}
],
"city : Amsterdam II": [
{
"range": "185.46.212.0/23",
"vpn": "amsterdam2-vpn.zscloud.net",
"gre": "185.46.212.36",
"hostname": "ams2.sme.zscloud.net",
"latitude": "52",
"longitude": "5"
},
{
"range": "147.161.228.0/23",
"vpn": "",
"gre": "",
"hostname": "",
"latitude": "52",
"longitude": "5"
},
{
"range": "165.225.240.0/23",
"vpn": "ams2-2-vpn.zscloud.net",
"gre": "165.225.240.42",
"hostname": "ams2-2.sme.zscloud.net",
"latitude": "52",
"longitude": "5"
},
{
"range": "147.161.172.0/23",
"vpn": "",
"gre": "165.225.240.42",
"hostname": "",
"latitude": "52",
"longitude": "5"
},
{
"range": "147.161.230.0/23",
"vpn": "",
"gre": "",
"hostname": "",
"latitude": "52",
"longitude": "5"
},
{
"range": "147.161.232.0/23",
"vpn": "",
"gre": "",
"hostname": "",
"latitude": "52",
"longitude": "5"
},
{
"range": "147.161.234.0/23",
"vpn": "",
"gre": "",
"hostname": "",
"latitude": "52",
"longitude": "5"
},
{
"range": "147.161.224.0/23",
"vpn": "",
"gre": "",
"hostname": "",
"latitude": "52",
"longitude": "5"
},
{
"range": "147.161.226.0/23",
"vpn": "",
"gre": "",
"hostname": "",
"latitude": "52",
"longitude": "5"
}
]
}
}
}
I am trying to get the name of the city + the nested hostname.
My Options:
I can either use Convertfrom-JSON and then somehow iterate over several unknown Keys and Properties.
Or I can use select-string and basically grep only the matching regex. Then put them into array etc.
Previously, I went with select-string against beautified JSON as it was easier.
Today, I have found out that not only Hostname but Hostname + City name may be required. Any idea how to extract them from the json?
I am on PS5.
Many Thanks, Aster