I need to read some information from json in Powershell. The problem that I am having is that after the "paths" section I cannot specify the next name e.g. what the path is called because it changes. Then after that I need to get the "get" section and then the "parameters" section and finally get the name and the required fields there.
I can get the hostname by using $info.host
and the paths like $info.paths
. Then I get the individual path names by looping through the path's to get each name like this.
foreach($item in $pName)
{
$item
}
But then that is as far as I can get I tried using $item.childItem but it doesn't work. Is there anyway to use something like $item.paths.childItems[$1].get.parameters and then get the name and the required field values?
The json looks like this:
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "Requirements.API"
},
"host": "replica.net",
"schemes": [
"http"
],
"paths": {
"/": {
"get": {
"tags": [
"Alive"
],
"operationId": "Alive_Get",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/requirements/email-docs": {
"get": {
"tags": [
"CustomerRequirement"
],
"operationId": "",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "name",
"in": "query",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/UploadResponse"
}
}
}
},
"deprecated": false
}
},