【发布时间】:2015-04-26 03:49:34
【问题描述】:
我有一个对象,其中属性的“键”将被动态设置...在 JSON 模式中定义它的正确方法是什么?
这就是我的对象的样子
{
"column_definitions": [
{
"Field_1": {
"type": "Numeric",
"isNullable": false
}
},
{
"Field_2": {
"type": "Boolean",
"isNullable": true
}
}
],
"row_values": [ ... ]
}
“column_definitions”的“key”总是动态的(它可以是“Field_1”,也可以是“Field_24”
在 JSON Schema 中定义它的正确方法是什么?
我不想只说“类型”:“对象”,因为我希望能够定义静态属性“类型”和“isNullable” 另外,我不能使用“oneOf”,因为我不知道“关键”可能是什么,并且没有设定的潜在值。
这是我目前所拥有的:
{
"$schema": "http://json-schema.org/draft-04/schema",
"title": "SomeSchema",
"description": "SomeDescription",
"type": "object",
"properties":
{
"column_definitions": { "type": ["array", "null"], "items": { "$ref": "#/definitions/columnDef" }, "readOnly": true },
"row_values": { "type": ["array", "null"], "items": { "type": "object" }, "readOnly": true }
},
"definitions": {
"columnDef" : {
"type": "object",
"properties": {
"THIS_IS_MY_DYNAMIC_PROPERTY": {
"type": "object",
"properties": {
"type": { "type" : ["string", "null"], "enum": ["Text", "Boolean", "Numeric", "DateTime"], "readOnly": true },
"isNullable": { "type" : ["boolean", "null"], "readOnly": true }
}
}
}
}
}
}
【问题讨论】:
-
你能解决吗?我现在也面临同样的情况
标签: json properties schema jsonschema