First, Is there any relation between JSONSchema and JSON-LD?
How do you create a schema in JSON-LD, and use it to validate some JSON-LD instances/records implementing each schema? Like how is schema.org defining their schemas? I don't see the connection after a few hours searching through JSON-LD.
CodePudding user response:
JSON-LD, in contrast to JSONSchema, is a concrete RDF syntax.
How do you create a schema in JSON-LD
The schemas (aka. vocabularies, ontologies) for RDF are defined using RDF, too (typically using the vocabularies RDFS and OWL).
So you could define your vocabulary, which you want to use in your JSON-LD data, in JSON-LD, too.
Whether you define your own vocabulary, or utilize an existing one (which is a good practice), using it in your JSON-LD works the same: you just reference the URI of the term (a property or a class/type).
Like how is schema.org defining their schemas?
The vocabulary Schema.org documents on https://schema.org/docs/developers.html where you can get their vocabulary definition. For example, the current version in the JSON-LD format can be downloaded from here: .jsonld.
(For creating vocabularies, typically the concrete RDF syntax Turtle gets used, because it’s easier to write/read. You can easily convert one RDF syntax to another one. The Schema.org vocabulary can also be downloaded as Turtle file: .ttl.)
use it to validate some JSON-LD instances/records implementing each schema
Using a vocabulary for your data doesn’t validate the data. It states what the data means, not what the data must look like.
For example, if you say that the property "hasTeacher" has the range "Human", and in your data you provide a dog as value, you made this dog belong to the class "Human".
(Format errors and some OWL restrictions can easily be catched, though. For example, if you state that the classes "Human" and "Dog" are disjoint.)
The vocabulary SHACL ( a SHACL-supporting tool) can be used for restrictions/validation.