user1751825
user1751825

Reputation: 4309

python jsonschema: Use "regex" module to validate "pattern"

I'm trying to use jsonschema for a schema which uses "pattern". However in this application, the "pattern" needs to be able to match unicode characters, which is not support by python's builtin "re" module.

for example

import jsonschema
import regex

schema = {
    "type": "object",
    "properties": {
        "name": {
            "type": "string",
            "pattern": "[\p{L}]+"
        },
    },
}

if (regex.compile(schema["properties"]["name"]["pattern"]).search("ᚠᛇᚻ")):
    print("It matched")

jsonschema.validate(instance={"name" : "ᚠᛇᚻ"}, schema=schema)

If I run this, the "regex" search works, but the schema validation fails with...

jsonschema.exceptions.SchemaError: '[\\p{L}]+' is not a 'regex'

So what I'm wondering is if there is some way to get jsonschema.validate to ignore the normal "pattern" validation and instead check the pattern with the "regex" module. I'm very new to jsonschema, so I don't quite know where to start.

Upvotes: 3

Views: 201

Answers (0)

Related Questions