简体   繁体   中英

validating json schema with nested objects

I'm trying to create a JSON schema that will validate that 'ewb_query' is an object, but I would like to specify that the values in the object are only strings (but any keys are valid, not just name and age like in the example below).

Ie I want values such as

"ewb_query":{"name":"jeff","age":32}, 

but not

"ewb_query":{"another_level":{...}},

This verifies that ewb_query is an object, but doesn't check that it's not nested.

'ewb_query' =>{
    type => 'object',
},

I tried this, but that seems to be invalid syntax:

'ewb_query' =>{
    type => 'object',
    properties => {
        type => 'string'
    },
},

Ideas? (pardon the perl syntax; that's what I'm using to generate my JSON schema)

This achieves what you need:

{ "type":"object", "additionalProperties":{"type":"string"} }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM