1

I am trying to migrate an application away from jsonschema.RefResolver, due to these deprecation messages when testing:

jsonschema.RefResolver is deprecated 
as of v4.18.0, in favor of the https://github.com/python-jsonschema/referencing library

Here is an example of the current code:

investigation_schema_path=os.path.join(
 BASE_DIR, "..", "resources", "schemas", base_schemas_dir, "core", "investigation_schema.json"
)
with open(investigation_schema_path) as fp
 investigation_schema = json.load(fp)
 # Code below is uses the deprecated jsonschema.RefResolver
 resolver = RefResolver("file://" + investigation_schema_path, investigation_schema)
 validator = Draft4Validator(investigation_schema, resolver=resolver)
 validator.validate(json_to_validate)

The code above validates all test data correctly.

Based on reading https://python-jsonschema.readthedocs.io/en/latest/referencing/ I have replaced the deprecated code with:

 schema = Resource.from_contents(investigation_schema)
 registry = schema @ Registry()
 validator = Draft4Validator(schema, registry)
 validator.validate(json_to_validate)

The result of this is that any test which should detect incorrect json_to_validate fails as no errors are reported: {'errors': [], 'warnings': [], 'validation_finished': True}

The tests which parse correct json_to_validate still appear to pass.

Presumably I have misunderstood how to use the new referencing library. Does anyone have any suggestions?

asked Oct 22, 2025 at 13:18
1
  • We need to see a complete code example including all required inputs (schema and json) and the expected output. Commented Oct 22, 2025 at 15:05

1 Answer 1

0

With a bit of trial and (lack of expected) error, it turns out that this syntax will cause validation to happen correctly:

with open(schema_path) as fp:
 schema = json.load(fp)
 validator = Draft4Validator(schema)
 validator.validate(json_in_need_of_validation)
answered Oct 23, 2025 at 11:00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.