title: Traverse JSON Schema in Powershell
body: <p>I'm trying to do some code-generation from JSON data. I'm getting some AWS backup data into a JSON file. I grab the first record and generate a json schema from that one line.</p>
  
  <p>When I load the schema in Powershell, I can't enumerate the properties because they are deserialzed as primary properties, not as an array within "properties". This looks like a json schema thing where the list of properties is shown as an object list and not an array, but I'm not sure.</p>
  
  <p>I'm guessing the Powershell JSON parser can't see an array there, so just makes them properties.</p>
  
  <p>I really don't want to manually traverse the schema JSON to get the list of properties and their types.</p>
  
  <p>schema.json</p>
  
  <pre class="lang-js prettyprint-override"><code>{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "",
    "type": "object",
    "properties": {
      "definition": {
        "type": "object",
        "properties": {
          "s": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "s"
        ]
      },
      "calcDefFilters": {
        "type": "object",
        "properties": {
          "l": {
            "type": "array",
            "uniqueItems": true,
            "minItems": 1,
            "items": {
              "required": [],
              "properties": {
                "m": {
                  "type": "object",
                  "properties": {
                    "field": {
                      "type": "object",
                      "properties": {
                        "s": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "required": [
                        "s"
                      ]
                    },
                    "value": {
                      "type": "object",
                      "properties": {
                        "s": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "required": [
                        "s"
                      ]
                    },
                    "operator": {
                      "type": "object",
                      "properties": {
                        "s": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "required": [
                        "s"
                      ]
                    }
                  },
                  "required": [
                    "field",
                    "value",
                    "operator"
                  ]
                }
              }
            }
          }
        },
        "required": [
          "l"
        ]
      },
      "calculationId": {
        "type": "object",
        "properties": {
          "s": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "s"
        ]
      },
      "calcDefParameters": {
        "type": "object",
        "properties": {
          "l": {
            "type": "array",
            "uniqueItems": true,
            "minItems": 1,
            "items": {
              "required": [],
              "properties": {
                "m": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "object",
                      "properties": {
                        "s": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "required": [
                        "s"
                      ]
                    },
                    "value": {
                      "type": "object",
                      "properties": {
                        "n": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "required": [
                        "n"
                      ]
                    },
                    "type": {
                      "type": "object",
                      "properties": {
                        "s": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "required": [
                        "s"
                      ]
                    }
                  },
                  "required": [
                    "name",
                    "value",
                    "type"
                  ]
                }
              }
            }
          }
        },
        "required": [
          "l"
        ]
      },
      "runId": {
        "type": "object",
        "properties": {
          "s": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "s"
        ]
      },
      "type": {
        "type": "object",
        "properties": {
          "s": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "s"
        ]
      },
      "externalId": {
        "type": "object",
        "properties": {
          "s": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "s"
        ]
      },
      "dealVersionId": {
        "type": "object",
        "properties": {
          "s": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "s"
        ]
      }
    },
    "required": [
      "definition",
      "calcDefFilters",
      "calculationId",
      "calcDefParameters",
      "runId",
      "type",
      "externalId",
      "dealVersionId"
    ]
  }
  </code></pre>
  
  <p>This is what I get in Powershell:</p>
  
  <pre class="lang-psh prettyprint-override"><code>[DBG]: PS C:\Scripts&gt;&gt; $prop
  
  
  definition        : @{type=object; properties=; required=System.Object[]}
  calcDefFilters    : @{type=object; properties=; required=System.Object[]}
  calculationId     : @{type=object; properties=; required=System.Object[]}
  calcDefParameters : @{type=object; properties=; required=System.Object[]}
  runId             : @{type=object; properties=; required=System.Object[]}
  type              : @{type=object; properties=; required=System.Object[]}
  externalId        : @{type=object; properties=; required=System.Object[]}
  dealVersionId     : @{type=object; properties=; required=System.Object[]}
  </code></pre>
  
  <p>Thoughts?</p>