Skip to content

JSON-LD

Are you tired of using 🐢 Turtles to write models? You are more familiar with JSON and YAML!

JSON-LD is a W3C standard to map JSON (and therefore YAML) to the RDF linked data model.

YAML

We can rewrite the greeting2.ttl from the Linked Data chapter as this greeting2.yaml:

id: greeting2
message: "hello"
object: world

---
id: world
wikipedia: https://en.wikipedia.org/wiki/Earth

Of course, we lost what uniquely identified our things… but JSON-LD Contexts can re-provide that, using this greeting-context.jsonld:

{
  "@context": {
    "@version": 1.1,
    "@vocab": "https://example.org/",
    "@base": "https://example.org/",
    "id": "@id",
    "object": {
      "@type": "@id"
    },
    "wikipedia": {
      "@type": "@id"
    }
  }
}

Combining these, Enola can recreate the same data model:

$ ./enola get --load="models/example.org/greeting2.yaml?context=models/example.org/greeting-context.jsonld" https://example.org/greeting2
@prefix calibre: <http://calibre.kovidgoyal.net/2009/metadata> .
@prefix marc: <http://id.loc.gov/vocabulary/> .
@prefix epubsc: <http://idpf.org/epub/vocab/sc/#> .
@prefix Iptc4xmpCore: <http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/> .
@prefix crs: <http://ns.adobe.com/camera-raw-settings/1.0/> .
@prefix exif: <http://ns.adobe.com/exif/1.0/> .
@prefix pdf: <http://ns.adobe.com/pdf/1.3/> .
@prefix photoshop: <http://ns.adobe.com/photoshop/1.0/> .
@prefix tiff: <http://ns.adobe.com/tiff/1.0/> .
@prefix xmp: <http://ns.adobe.com/xap/1.0/> .
@prefix xmpBJ: <http://ns.adobe.com/xap/1.0/bj/> .
@prefix xmpMM: <http://ns.adobe.com/xap/1.0/mm/> .
@prefix xmpRights: <http://ns.adobe.com/xap/1.0/rights/> .
@prefix xmpDM: <http://ns.adobe.com/xmp/1.0/DynamicMedia/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix onix: <http://www.editeur.org/ONIX/book/codelists/current.html#> .
@prefix opf: <http://www.idpf.org/2007/opf#> .
@prefix epub: <http://www.idpf.org/2007/ops#> .
@prefix media: <http://www.idpf.org/epub/vocab/overlays/#> .
@prefix a11y: <http://www.idpf.org/epub/vocab/package/a11y/#> .
@prefix msv: <http://www.idpf.org/epub/vocab/structure/magazine/#> .
@prefix rendition: <http://www.idpf.org/vocab/rendition/#> .
@prefix prism: <http://www.prismstandard.org/specifications/3.0/PRISM_CV_Spec_3.0.htm#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xhtml: <http://www.w3.org/1999/xhtml/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xmpTPg: <https://developer.adobe.com/xmp/docs/XMPNamespaces/xmpTPg/> .
@prefix enola: <https://enola.dev/> .
@prefix ex: <https://example.org/> .
@prefix schema: <https://schema.org/> .

ex:greeting2 ex:message "hello";
  ex:object ex:world;
  enola:origin <file:///home/runner/work/enola/enola/models/example.org/greeting2.yaml?context=models%2Fexample.org%2Fgreeting-context.jsonld> .

Generating documentation will look the same as in the original Linked Data chapter, using this:

$ ./enola docgen --load="models/example.org/greeting2.yaml?context=models/example.org/greeting-context.jsonld" --output=/tmp/models/ --no-index

More

Tools > JSON-LD has more reference documentation about JSON-LD in Enola.