如何为对象中的 JSON 字符串字段定义 JSON 架构?

问题描述 投票:0回答:1

我有一个 JSON 对象,其中一个字段包含 JSON 字符串。我需要编写一个 JSON 架构来验证此 JSON 字符串字段。这是我正在使用的 JSON 对象的示例:

{
  "id": 1,
  "name": "John Doe",
  "details": "{\"age\": 30, \"email\": \"[email protected]\"}"
}

“details”是一个具有 JSON 对象的字符串。我想验证细节以具有特定的结构。

我目前拥有的 JSON 模式:

"type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "details": {
      "type": "string",
<Schema to add validation>

如何在 JSON 模式本身中处理这个问题?

json jsonschema json-schema-validator jsonschema2pojo
1个回答
0
投票

这可以使用关键字

contentSchema
来完成,但该关键字只是一个 注释,不需要用于规范的验证。实现可能会强制执行定义的模式。

{
"properties": {
  "details": { 
    "type": "string",
    "contentMediaType": "application/json",
    "contentSchema": {
      "type": "object",
      "properties": {
        "age": { "type": "integer" },
        "email": { "type": "string" }
      }
     }
   }
  }
}
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.