Is there any way to use a relative file path for JSON schemas ?
Below mentioned syntax not work in vscode :
$schema = "file:///foo.schema.json"
And this one works :
$schema = "file:///c:/test/foo.schema.json"
Is there any way to use a relative file path for JSON schemas ?
Below mentioned syntax not work in vscode :
$schema = "file:///foo.schema.json"
And this one works :
$schema = "file:///c:/test/foo.schema.json"
If you have a scheme like file:
, that forms a full (absolute) URI, instead of a (relative) URI Reference.
A full URI is supposed to mean the same thing everywhere, so it doesn't make sense to have a relative file path. Also note that file:///foo.schema.json
is the same thing as file://localhost/foo.schema.json
To write a relative filename, use a URI Reference, like foo.schema.json
. This will be resolved against a URI base — typically the URI of the document — to form the correct URI, even if the file moves on the filesystem.
For example, if you use this in a file at c:\test\main.json
, then the Base URI will be file:///c:/test/main.json
, and the URI Reference will resolve to file:///c:/test/foo.schema.json
, which is correct.
See File Uri Scheme and Relative Files for more information on this.