Help with Powershell -json
Help with Powershell -json
(OP)
I am new to Powershell.
I have the following script. I am trying to determine the powershell "code" to identify which, if any, "field" is an array or hashtable.
The result is
What property/parameter??? identifies img, and entries as "fields" whose values are arrays???
I'm trying to identify such fields (subarrays) without explicitly knowing each and every field name.
Thanks in advance.
UPDATE: I have found an answer to this.
which gives this result:
I have the following script. I am trying to determine the powershell "code" to identify which, if any, "field" is an array or hashtable.
CODE -->
$txt = @" { "id": "02002010", "booktitle": "", "pagetitle": "Demo Page", "parent": "02002000", "img": [ { "imgfile": "02A.png", "imgname": "02A.png" } ], "fmt": "", "entries": [ { "itemid": "1", "partnumber": "1234567", "partdescription": "Washer", "partqty": "2", "Manufacturer": "ACME", "TYPE": "Stainless", "partdescriptionlocal": "Washer" }, { "itemid": "2", "partnumber": "98765-B", "partdescription": "Screw", "partqty": "8", "Manufacturer": "Widget Inc", "TYPE": "Galv", "partdescriptionlocal": "Screw" }] } "@ $json= ConvertFrom-Json -inputobject $txt foreach($pct in $json) { $pct}
The result is
CODE -->
id : 02002010 booktitle : pagetitle : Demo Page parent : 02002000 img : {@{imgfile=02A.png; imgname=02A.png}} fmt : entries : {@{itemid=1; partnumber=1234567; partdescription=Washer; partqty=2; Manufacturer=ACME; TYPE=Stainless; partdescriptionlocal=Washer}, @{itemid=2; partnumber=98765-B; partdescription=Screw; partqty=8; Manufacturer=Widget Inc; TYPE=Galv; partdescriptionlocal=Screw}}
What property/parameter??? identifies img, and entries as "fields" whose values are arrays???
I'm trying to identify such fields (subarrays) without explicitly knowing each and every field name.
Thanks in advance.
UPDATE: I have found an answer to this.
CODE
$json= ConvertFrom-Json -inputobject $txt ForEach($pct in $json) { $pct.psobject.properties.name | foreach-object { [PSCustomObject]@{ Property = $_ Type = $pct.$_.gettype().basetype } } }
which gives this result:
CODE
Property Type -------- ---- id System.Object booktitle System.Object pagetitle System.Object parent System.Object img System.Array fmt System.Object entries System.Array