VMware Cloud Community
getvrohelp
Enthusiast
Enthusiast

parsing json

Hi guys and gals,

     I hope you can help me out with something that I thought would be simple. I am running an external powershell script. That is fine. I am then returning it as json to get the data I need. I have the output below but I can only get part of the data and no matter what I try I am unable to get "InterfaceAlias", "IPv4Address"..... 2 of the items I would like to get. I'll do my best to detail below. I am using version 8.2.

Below is the json output. After the "HOST OUTPUT END". I am able to get "http://schemas.microsoft.com/powershell/2004/04", but nothing beyond that. Nothing I try is working. I am no expert so I am here to ask for help. 

var jsonData = cleanJson.Objs.xmlns ;

System.log("jsonData: " + jsonData) ;

the above 2 lines gives me the http://schemas................. data but I need interfaceindex, ipv4address,interfacealias that you see in the host output. I have tried to dot walk it, for loop it. I just don't know what I need so I'm hoping you guys will help me out and let me know what I need to do to get this data? I am sure I haven't provided all the information needed

2021-04-15 12:42:49.660 -07:00INFO__item_stack:/item4
2021-04-15 12:42:54.284 -07:00INFO__item_stack:/item3
2021-04-15 12:42:54.287 -07:00INFOthis is the script and args & "c:\psscripts\testps_template.ps1" -computer vra76-jumpbox
2021-04-15 12:42:57.563 -07:00INFO------- HOST OUTPUT ---------------------------
2021-04-15 12:42:57.565 -07:00INFO

InterfaceIndex       : 10
IPv4Address          : 192.168.225.145
InterfaceAlias       : Ethernet0
InterfaceDescription : Intel(R) 82574L Gigabit Network Connection
Status               : Up






2021-04-15 12:42:57.566 -07:00INFO-------- HOST OUTPUT END --------------------------
2021-04-15 12:42:57.572 -07:00INFOcleanJson:{"Objs":{"xmlns":"http://schemas.microsoft.com/powershell/2004/04","Version":"1.1.0.1","Obj":{"MS":{"S":[{"N":"IPv4Address","content":"192.168.225.145"},{"N":"InterfaceAlias","content":"Ethernet0"},{"N":"InterfaceDescription","content":"Intel(R) 82574L Gigabit Network Connection"},{"N":"Status","content":"Up"}],"I32":{"N":"InterfaceIndex","content":10}},"TN":{"T":["Selected.NetIPConfiguration","System.Management.Automation.PSCustomObject","System.Object"],"RefId":0},"RefId":0}}}
2021-04-15 12:42:57.573 -07:00INFOdivisions: http://schemas.microsoft.com/powershell/2004/04
2021-04-15 12:42:57.574 -07:00INFOReferenceError: "alert" is not defined.
2021-04-15 12:42:57.586 -07:00INFO__item_stack:/item0

 

 

0 Kudos
1 Reply
getvrohelp
Enthusiast
Enthusiast

I was able to work this out. I learned about null 4 which really helped me see where the data was at and what it was.

 

System.log(JSON.stringify(cleanJson, null4)) which provided a much cleaner output and from that I could wrap my head around it.
 
getvrohelp_0-1618527208716.png

 

0 Kudos