Dictionary-like JSON schema

后端 未结 1 395
青春惊慌失措
青春惊慌失措 2020-12-25 11:10

I have a json object that can contain any number of nested objects with certain specification, for example:

{
  \"Bob\": {
    \"age\": \"42\",
    \"gender\         


        
1条回答
  •  一个人的身影
    2020-12-25 11:54

    additionalProperties is your keyword:

    {
        "type" : "object",
        "additionalProperties" : {
            "type" : "object",
            "required" : [
                "age",
                "gender"
            ],
            "properties" : {
                "age" : {
                    "type" : "string"
                },
                "gender" : {
                    "type" : "string"
                }
            }
        }
    }
    

    additionalProperties can have following values with different meanings:

    • "additionalProperties": false No more properties are allowed at all.
    • "additionalProperties": true Any more properties are allowed. This is the default behavior.
    • "additionalProperties": {"type": "string"} Additional properties (of arbitrary name) are allowed, if they have value of given type ("string" here).
    • "additionalProperties": {*any schema*} Additional properties must satisfy the provided schema, such as the example provided above.

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