-
I am making test code that validates JSON by schema. When I run it, the error occurs:
Is it the library issue or do I do something wrong? Code: import json
import jsonschema
import referencing
def main():
with open('data.json', 'r') as f:
json_data = json.load(f)
with open('schema.json', 'r') as f:
json_schema = json.load(f)
print("Json data:", json_data, sep='\n')
res = referencing.Resource.from_contents(json_schema)
reg = referencing.Registry().with_resource(res.id(), res).crawl()
jsonschema.validate(json_data,
reg["https://t1m013y.github.io/jsonschema/test_person"].contents,
None,
reg)
if __name__ == '__main__':
main()
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://t1m013y.github.io/jsonschema/test001.json",
"$defs": {
"nonNegativeInt": {
"$id": "https://t1m013y.github.io/jsonschema/test_nonNegativeInt",
"type": "integer",
"minimum": 0
},
"person": {
"$id": "https://t1m013y.github.io/jsonschema/test_person",
"properties": {
"name": {"type": "string"},
"age": {"$ref": "https://t1m013y.github.io/jsonschema/test_nonNegativeInt"}
}
}
}
}
{
"name": "John",
"age": 3
} Full error log:
|
Beta Was this translation helpful? Give feedback.
Answered by
Julian
Apr 26, 2025
Replies: 1 comment 1 reply
-
You want the Specifically you want: jsonschema.validate(json_data,
reg["https://t1m013y.github.io/jsonschema/test_person"].contents,
registry=reg) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
t1m013y
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You want the
registry
argument, not the deprecated resolver argument which is what you're getting by passing the registry positionally like that.Specifically you want: