I am trying to write a json schema including the feature to check if a path is valid and exist.
For example I want to validate this json:
{
"paths": ["/path/to_check", "../path/not/valid", "../../path/exists"]
}
My current schema is:
{
"type": "object",
"properties": {
"paths": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
Is there a way to indicate that items must contain valid/existing paths?
You can use regex, but there's no way to determine if a path is a real path according to a file system. JSON Schema works with JSON data... that's all, nothing more. It has no notion of a file system.
I've been googling for the same thing and was coming to the same conclusion that @Relequestual posted (who is the authority on such things).
What may be of interest is that the pydantic library extends their JSON Schema with a bunch of extensions for complex string
sub-types, including file-path
, directory-path
and path
(and many, many more).
This could be useful either directly, or to adopt as a quasi-standard for a custom implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With