允许 属性 定义 Json 模式的任何字符串
Allow any string for property definition Json Schema
我正在尝试使用 json 架构来验证一些简单的 json。我有以下内容:
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"outputs": {
"type": "object",
"properties": {
"ANYSTRING": {
"type": "string",
"properties": {
"label": { "type": "string" },
"otherLabel": { "type": "string" }
}
}
}
}
}
}
基本上,我希望以下任何一项都有效:
{
"outputs": {
"this is a sample string": { "label": "test" },
"another string": { },
"and one last one": { "otherLabel": "dummy" }
}
}
(如何)我能否将此通配符字符串 属性 在上面表示为“ANYSTRING”?
我想你可以使用 additionalProperties。旁注:“字符串”类型的事物不能有属性,但“对象”可以。
"outputs": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"label": { "type": "string" }
}
}
}
- Shawn Silverman(JsonSchema Slack 频道)
我正在尝试使用 json 架构来验证一些简单的 json。我有以下内容:
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"outputs": {
"type": "object",
"properties": {
"ANYSTRING": {
"type": "string",
"properties": {
"label": { "type": "string" },
"otherLabel": { "type": "string" }
}
}
}
}
}
}
基本上,我希望以下任何一项都有效:
{
"outputs": {
"this is a sample string": { "label": "test" },
"another string": { },
"and one last one": { "otherLabel": "dummy" }
}
}
(如何)我能否将此通配符字符串 属性 在上面表示为“ANYSTRING”?
我想你可以使用 additionalProperties。旁注:“字符串”类型的事物不能有属性,但“对象”可以。
"outputs": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"label": { "type": "string" }
}
}
}
- Shawn Silverman(JsonSchema Slack 频道)