Generate a JSON schema

This utility generates a JSON Schema document from a SHACL specification. Detailed documentation is available below.

  Shapes

Remove Select file Change
You can select multiple files. Supported extensions : .rdf, .ttl, .n3, .trig. Other extensions will be treated as RDF/XML
URL of an RDF file. Same extensions as file upload are supported.
Supported syntaxes : Turtle, RDF/XML, JSON-LD, TriG, TriX, N-Quads. We recommend Turtle.

  Options

The URI of the Node Shape that will be used as root in the JSON schema generation

Documentation

JSON Schema document generation algorithm

The algorithm follow these steps to generate the JSON Schema:

Constant declarations
  • A declaration is always added for @context since we are targeting JSON-LD
  • schema version is always set to https://json-schema.org/draft/2020-12/schema
  • a container_language declaration is always added with a patternProperty declaration with properties being language codes to deal with "@container": "language" properties.
Schema header
  • title is populated from an owl:Ontology dct:title or rdfs:label
  • version is populated from an owl:Ontology owl:versionInfo
  • description is populated from an owl:Ontology dct:description
Node shapes conversion

Each node shape with at least one non-deactivated property shape is turned into an object schema in the $defs section of the schema, with the URI local name as the name of the schema. Node shapes with no non-deactivated property shapes are turned into string schemas being simple iri-reference.

  • title is populated from the node shape rdfs:label
  • description is populated from the node shape rdfs:comment
  • There is always a required id property
  • If node shape is closed, then additionalProperties is set to false
  • Then each property shape is processed as described below
Property shapes conversion

Non-deactivated property shapes are processed this way:

  • The corresponding JSON key is read from shacl-play:shortName annotation, otherwise the local name of the property in sh:path is used as the JSON key
  • title is populated from the property shape sh:name
  • description is populated from the property shape sh:description
  • The property shape is mapped to a schema this way:
    • If the property shape has an sh:hasValue, a const schema is created with the value
    • If the property shape has an sh:in, an enum schema is created with the list of possible values
    • If the property shape has an sh:node, then :
      • If the property shape is annotated with shacl-play:embed shacl-play:EmbedNever, then a string schema with format iri-reference is generated
      • Otherwise, create a $ref schema with a reference to one of the schemas in the #/$defs section
      • If there is no sh:maxCount or a sh:maxCount that is > 1, then wrap the generated schema into an array schema
    • If the property shape has an sh:pattern, then turn it into a string schema with a pattern constraint.
    • If the property shape has an sh:datatype (with a consistent value for the same property across the SHACL spec), then:
    • If the property shape has an sh:nodeKind pointing to sh:IRI, generate a string schema of format iri-reference.
    • Otherwise, return an empty schema
  • If the sh:minCount is > 0, the JSON key is added to the list of requiredProperties of the schema
Root node shape

With the provided root node shape IRI, create a reference to the corresponding schema from the #/$defs section.