0
schema = { "type" : "object", 
              "properties" : 
                   { "price" : {"type" : "array", 
                      "items" : { "type" : "string" ,  "pattern": "^[A-Za-z0-9_]*$" }},
                     }, 
             }

from jsonschema import validate
validate(instance={"price" : ["test","34"]}, schema=schema)

The above code validates the property price having non spaced string array items. Is it possible to validate the property even if we don't know the incoming property name ?

Possibly like below

schema = { "type" : "object", 
              "properties" : 
                   {  "type" : "array", 
                      "items" : { "type" : "string" ,  "pattern": "^[A-Za-z0-9_]*$" },
                   }, 
             }

from jsonschema import validate
validate(instance={"price" : ["test","34"]}, schema=schema)
validate(instance={"marks" : ["test","34"]}, schema=schema)
ankitj
  • 335
  • 4
  • 13

1 Answers1

0

Yes, you can use additionalProperties to provide a generic schema that all objects must pass, no matter what the property name.

You can also constrain the property names using a pattern - see "patternProperties" at https://json-schema.org/understanding-json-schema/reference/object.html.

Ether
  • 53,118
  • 13
  • 86
  • 159
  • Thank you @Ether. This example helped a lot https://stackoverflow.com/questions/32044761/json-schema-with-unknown-property-names too. – ankitj Oct 14 '20 at 19:06