Apache Jena ShEx

jena-shex is an implementation of the ShEx (Shape Expressions) language.

This implementation is experimental, starting with Jena 4.2.0. Please send usage reports and experience to users@jena.apache.org.


jena-shex reads ShExC (the compact syntax) files.

Not currently supported:

  • semantic actions

Blank node label validation is meaningless in Jena because a blank node label is scoped to the file, and not retained after the file has been read.

Command line

The command shex introduces shex operations; it takes a sub-command argument.

To validate:

shex validate --schema SCHEMA.shex --map MAP.shexmap --data DATA.ttl
shex v -s SCHEMA.shex -m MAp.shexmap -d data.ttl

To parse a file:

shex parse FILE
shex p FILE

which writes out the parser results in a text format.


The package org.apache.jena.shex has the main classes.

  • Shex for reading ShEx related formats.
  • ShexValidation for validation.

API Examples



    public static void main(String ...args) {
        String SHAPES     = "examples/schema.shex";
        String SHAPES_MAP = "examples/shape-map.shexmap";
        String DATA       = "examples/data.ttl";

        System.out.println("Read data");
        Graph dataGraph = RDFDataMgr.loadGraph(DATA);

        System.out.println("Read schema");
        ShexSchema shapes = Shex.readSchema(SHAPES);

        // Shapes map.
        System.out.println("Read shapes map");
        ShexMap shapeMap = Shex.readShapeMap(SHAPES_MAP);

        // ShexReport
        ShexReport report = ShexValidator.get().validate(dataGraph, shapes, shapeMap);

        // Print report.