未知属性的JSON架构,这些属性是具有日期-时间属性名称的对象



以下是我试图为构建架构的一些示例数据

{
"measurement data": {
"interval data": {
"2022-09-14T16:00:00+0:00": {
"duration": 300,
"Leq": 65.2
},
"2022-09-14T16:05:00+0:00": {
"duration": 300,
"Leq": 64.3
},
"2022-09-14T16:10:00+0:00": {
"duration": 300,
"Leq": 61.1
}
}
}
}

间隔数据的属性是具有ISO 8601格式的日期-时间字符串的属性名称的对象。实现这一点的最佳方式是什么?

我想我可以使用patternProperties和正则表达式来匹配ISO8601字符串。我在下面尝试了一下(我遇到了一个逃避问题,所以它坏了(。

JSON模式中已经有一个名为"date-time"的格式定义,使用起来很方便,但我不知道如何在patternProperties中使用它。

{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "http://example.com/example.json",
"type": "object",
"default": {},
"title": "Root Schema",
"required": [
"measurement data"
],
"properties": {
"measurement data": {
"type": "object",
"default": {},
"title": "The measurement data Schema",
"required": [
"interval data"
],
"properties": {
"interval data": {
"type": "object",
"default": {},
"title": "The interval data Schema",
"patternProperties": {
"^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$": {
"type": "object",
"default": {},
"title": "The timestamp Schema",
"required": [
"duration",
"Leq"
],
"properties": {
"duration": {
"type": "integer",
"default": 0,
"title": "The duration Schema",
"examples": [
300
]
},
"Leq": {
"type": "number",
"default": 0,
"title": "The Leq Schema",
"examples": [
65.2
]
}
}
}
}
}
}
}
}
}

您可以将属性名称的模式与(drum-roll(propertyNames关键字一起使用:

{
"propertyNames": { "format": "date-time" },
"additionalProperties": {
... schema for the property values here ...
}
}

参见https://json-schema.org/understanding-json-schema/reference/object.html#property-名称

正则表达式从/开始,到/结束。因此,也许不要:
"^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$"
尝试:
"/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/"

相关内容

  • 没有找到相关文章

最新更新