Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Help with Powershell -json

Help with Powershell -json

Help with Powershell -json

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.

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) { 

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.


$json=  ConvertFrom-Json -inputobject $txt
ForEach($pct in $json) { 
$pct.psobject.properties.name | 
foreach-object {
   Property = $_
   Type = $pct.$_.gettype().basetype

which gives this result:


Property  Type         
--------  ----         
id        System.Object
booktitle System.Object
pagetitle System.Object
parent    System.Object
img       System.Array 
fmt       System.Object
entries   System.Array 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close