Derive an OWL Ontology from JSON Schema
There was some content I needed to inject into an RDF graph where the original data was in JSON files. I first noted the surprisingly well-defined form of the JSON data. Attached was a "schema.json" file which contained stuff similar to an ontology and contained this reference:
JSON Schema
Under https://json-schema.org an approach is documented that comes as close to a semantic ontology as it gets in JSON. And, in my opinion, that might be quite close already for many simpler use cases... even though it would not go further than GraphQL goes compared to SPARQL.
The URL https://json-schema.org/draft/2020-12/schema directly gets you the JSON Schema definition downloaded as a .json file. The JSON Schema from my use case builds on this in a similar way an OWL-Ontology refers to the basic OWL ontology file.
Mapping the JSON Schema to OWL step by step
Fair enough, but how to transform the data under JSON Schema into RDF based on OWL Ontology?
Luckily I found a research paper dealing with exactly this topic:
"Translating JSON Schema logics into OWL axioms for unified data validation on a digital manufacturing platform" https://doi.org/10.1016/j.promfg.2018.12.030
Approach for the mapping
For this section, I simplified the approach from the paper mentioned above.
a) From the JSON Schema, every object needs to be mapped to an OWL class.
You need an already existing ontology for this or create one at this point. This is a manual process. You look at the objects in your data and you know your ontology, and so you decide which object is resmbled by which OWL Class.
b) Relations are less obvious as they are not directly stated in data based on JSON Schema. There, relations happen implicitly as a logical "link" between objects. In RDF and OWL, relations are explicitly stated (which is one reason that makes this technique powerful). Attributes (aka data properties) for the ontology must be mapped from the Schema properties as well.
c) Take a close look at the objects and data types in the JSON Schema file. It may be crucial for a given use case to exactly preserve the original intention of the datatypes defined in the Schema file (JSON validation keywords) and find appropriate matches for your ontology. In my case it was simple, everything was "string" :-)
Now you have an ontology that directly corresponds to the source data and can be used for automated JSON to RDF mapping.
Subscribe to my newsletter
Read articles from Sparkle.Select directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by