Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to constraint maximum length of keys of an object in JSON schema

Tags:

jsonschema

I would like to constraint maximum length of a key of the property which type is object. All of its values are generated in runtime and I'd like to spot a misbehavior as soon as possible by validating document before further processing.

like image 753
Kentzo Avatar asked Dec 20 '25 19:12

Kentzo


1 Answers

You can make it like this:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "Object with 10 char max properties",
    "type": "object",
    "additionalProperties": false,
    "minProperties": 1,
    "patternProperties": 
    {
        "^[a-z]{0,10}$": 
        { 
            "description": "Some description", 
            "type": "string"
        }
    }
}        
like image 84
Amid Avatar answered Dec 24 '25 12:12

Amid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!