JSON Schema definition for array of objects

后端 未结 1 2000
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 14:05

I\'ve seen this other question but it\'s not quite the same, and I feel like my issue is simpler, but just isn\'t working.

My data would look like this:

         


        
1条回答
  •  清歌不尽
    2021-02-01 14:52

    You have defined your schema correctly, except that it doesn't match the data you say you are validating. If you change the property names to match the schema, you still have one issue. If you want to allow "toll" and "message" to be null, you can do the following.

    {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "loc": {
            "type": "string"
          },
          "toll": {
            "type": ["string", "null"]
          },
          "message": {
            "type": ["string", "null"]
          }
        },
        "required": [
          "loc"
        ]
      }
    }
    

    However, that isn't related to the error message you are getting. That message means that data you are validating is not an array. The example data you posted should not result in this error. Are you running the validator on some data other than what is posted in the question?

    0 讨论(0)
提交回复
热议问题