我正在嘗試從JSON數據做一些代碼生成。我將一些AWS備份數據導入JSON文件。我抓住第一條記錄並從那一行生成一個json模式。在PowerShell中遍歷JSON Schema
當我在Powershell中加載模式時,我無法枚舉屬性,因爲它們被反序列化爲主屬性,而不是作爲「屬性」中的數組。這看起來像一個JSON模式的東西,其中的屬性列表顯示爲一個對象列表而不是一個數組,但我不知道。
我猜Powershell JSON解析器不能在那裏看到一個數組,所以只是使它們的屬性。
我真的不想手動遍歷模式JSON來獲取屬性及其類型的列表。
schema.json
{
"$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"
]
}
這是我得到在PowerShell中:
[DBG]: PS C:\Scripts>> $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[]}
的思考?
EHH,'properties'是*不*數組,一個JSON語法將'屬性:[...]'不'屬性:{...}' –
對。所以JSON模式不會在數組中做屬性。那我不走運了? –
[在自定義對象中循環每個NoteProperty](// stackoverflow.com/q/27642169) – wOxxOm