gpt4 book ai didi

java - 如何验证 json 模式中的 UUID 属性字段?

转载 作者:行者123 更新时间:2023-12-05 05:46:29 25 4
gpt4 key购买 nike

   {
"status": 200,
"id": "123e4567-e89b-12d3-a456-426655440000",
"shop": {
"c73bcdcc-2669-4bf6-81d3-e4ae73fb11fd": {
"123e4567-e89b-12d3-a456-426655443210": {
"quantity": {
"value": 10
}
},
"123e4567-e89b-12d3-a456-426655443211": {
"quantity": {
"value": 20
}
}
}
}
}

这是我的 json 响应。我想验证字段“c73bcdcc-2669-4bf6-81d3-e4ae73fb11fd”,“123e4567-e89b-12d3-a456-426655443210”和“123e4567-e89b-12d3-a456-426655443211”,每次点击时都是唯一的端点。

最佳答案

基于@pxcv7r 的回答:

To validate UUID in particular, you may use format in JSON schema, which provides built-in support for the UUID syntax: { "type": "string", "format": "uuid" }

See https://json-schema.org/understanding-json-schema/reference/string.html

此外,您可以使用 "propertyNames" 的组合和 "unevaluatedProperties"避免需要任何正则表达式:

{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"properties": {
"status": {
"type": "integer"
},
"id": {
"type": "string",
"format": "uuid"
},
"shop": {
"type": "object",
"minProperties": 1,
"maxProperties": 1,
"propertyNames": {
"format": "uuid"
},
"unevaluatedProperties": {
"type":"object",
"minProperties": 1,
"propertyNames": {
"format": "uuid"
},
"unevaluatedProperties": {
"title": "single variant of a shop",
"type": "object",
"properties": {
"quantity": {
"type": "object",
"properties": {
"value": {
"type": "integer"
}
}
}
}
}
}
}
}
}

关于java - 如何验证 json 模式中的 UUID 属性字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71170652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com