一见

JSON的schema进阶

要求JSON中的所有keys名只能由下划线、字母和数字组成,且必须以下划线或字母打头:

{

  "type": "object",

  "propertyNames": {

    "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"

  }

}

 

要求JSON中的所有以“I_”打头的keysvalues只能为整数:

{

  "type": "object",

  "patternProperties": {

    "^I_": { "type": "integer" }   

  },

  "additionalProperties": false

}

 

要求JSON中所有的values只能为字符串:

{

  "type": "object",

  "additionalProperties": { "type": "string" }

}

 

以上两种的结合:

{

  "type": "object",

  "properties": {

    "builtin": { "type": "number" }

  },

  "patternProperties": {

    "^S_": { "type": "string" },

    "^I_": { "type": "integer" }

  },

  "additionalProperties": { "type": "string" }

}

 

以上内容来源:

https://json-schema.org/understanding-json-schema/reference/object.html

posted on 2020-07-21 14:42  -见  阅读(371)  评论(0编辑  收藏  举报

导航