4

I am using a JSON Schema to validate a file. This is somehat similar to an XML XSD.

I have a few questions concerning the id field.

  • Does the schema still works without network connection ?
  • The URL in the id should be accessible from a web browser ? i.e. if 'id' = "https://example.com/question", does this mean that we should be able to access the schema from a browser by going to https://example.com/question ?

I am a bit lost on this subject. I know that it is best practice to have an id property as a unique identifier for every schema, and that this gets most useful when creating a complex schema with different schemas that reference each other.

But I am not sure if we need to assign a URL to the id field or not. And I'm also lost concerning the implication of having this URL for the schema.

Thank you very much for your help

T code
  • 447
  • 2
  • 7
  • 12

2 Answers2

4

Main purpose of id ($id since draft-06) is to organize scope for $ref resolving.

$id does not have to be an existing HTTP resource. Identified schema can be even defined in another one (example in spec test suite).

JSON Schema spec expects that validator should be able to resolve references based on $ids defined in current schema. Remote references should be also resolved, but there are no limitations on how exactly it should happen.

In many cases network interactions during validations are very unwanted due to high latency. Most implementations provide you a way to preload/define schema resources by $id explicitly before validation.

According to spec root schema SHOULD have $id which is an absolute URI, but whether or not it should be accessible with HTTP client is up to you and your validator.

vearutop
  • 3,924
  • 24
  • 41
0

$id is only defined to be an URI.

http://json-schema.org/draft-07/json-schema-core.html#rfc.section.8.2

See RFC-3986 Uniform Resource Identifier (URI): Generic Syntax

https://www.rfc-editor.org/rfc/rfc3986

"A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource."

A nice write-up by Daniel Messier provides a clear explanation of the nature of an URI - which can just be an URN - but may also be a valid URL

https://danielmiessler.com/study/url-uri/

Community
  • 1
  • 1