JSON schema $ref does not work for relative path JSON schema $ref does not work for relative path json json

JSON schema $ref does not work for relative path


Your references are incorrect. If the referenced schemes are in the same folder, use simple relative path references like:

"child": {"$ref": "child.json"},"reason": {"$ref": "parent.json"}

If you're using jsonschema for validation, don't forget to set a reference resolver in order to resolve the paths to referenced schemas:

import osfrom jsonschema import validate, RefResolverinstance = {}schema = grandpa# this is a directory name (root) where the 'grandpa' is locatedschema_path = 'file:///{0}/'.format(      os.path.dirname(get_file_path(grandpa)).replace("\\", "/"))resolver = RefResolver(schema_path, schema)validate(instance, schema, resolver=resolver)