Skip to content

JSON-LD

Enola supports JSON-LD.

Direct Load

Enola can directly --load JSON & YAML, given a JSON-LD Context; see Tutorial.

Conversions

Enola Rosetta can convert model resources among different formats using JSON-LD; e.g. from picasso.yaml:

{ % include "../../../test/picasso.yaml" start="# limitations under the License.\n" % }

or from picasso.json:

{
    % include "../../../test/picasso.json" %
}

with a picasso-context.jsonld:

{
    % include "../../../test/picasso-context.jsonld" %
}

YAML to RDF Turtle 🐢

$ ./enola rosetta --in="test/picasso.yaml?context=test/picasso-context.jsonld" --out="fd:1?mediaType=text/turtle"
@base <fd:1?mediaType=text/turtle> .

_:b0 <http://example.enola.dev/city> "Barcelona";
  <http://example.enola.dev/street> "31 Art Gallery" .

<http://example.enola.dev/Dalí> a <http://example.enola.dev/Artist>;
  <http://xmlns.com/foaf/0.1/firstName> "Salvador", "Domingo", "Felipe", "Jacinto";
  <https://schema.org/birthDate> "1904-05-11"^^<https://schema.org/Date> .

<http://example.enola.dev/Picasso> a <http://example.enola.dev/Artist>;
  <http://example.enola.dev/homeAddress> _:b0;
  <http://www.w3.org/ns/locn#location> "Spain"@en;
  <http://xmlns.com/foaf/0.1/firstName> "Pablo" .

JSON to RDF Turtle 🐢

$ ./enola rosetta --in="test/picasso.json?context=test/picasso-context.jsonld" --out="fd:1?mediaType=text/turtle"
@base <fd:1?mediaType=text/turtle> .

_:b0 <http://example.enola.dev/city> "Barcelona";
  <http://example.enola.dev/street> "31 Art Gallery" .

<http://example.enola.dev/Dalí> a <http://example.enola.dev/Artist>;
  <http://xmlns.com/foaf/0.1/firstName> "Salvador", "Domingo", "Felipe", "Jacinto";
  <https://schema.org/birthDate> "1904-05-11"^^<https://schema.org/Date> .

<http://example.enola.dev/Picasso> a <http://example.enola.dev/Artist>;
  <http://example.enola.dev/homeAddress> _:b0;
  <http://www.w3.org/ns/locn#location> "Spain"@en;
  <http://xmlns.com/foaf/0.1/firstName> "Pablo" .

JSON to JSON-LD

$ ./enola rosetta --in="test/picasso.json?context=test/picasso-context.jsonld" --out="fd:1?mediaType=application/ld+json" | head -7
[
    {
        "@id": "_:b0",
        "http://example.enola.dev/city": [
            {
                "@value": "Barcelona"
            }

Tips

Use something like this to map a string, e.g. a machine hostname in a JSON, to a link in RDF:

{
    "@context": {
        "@version": 1.1,
        ...
        "machine": {
            "@id": "http://example.org/host",
            "@type": "@id",
            "@context": {
                "@base": "http://example.org/host/"

Override Nested

In order to “override” the mapping for a “nested” JSON property, JSON-LD lets us define embedded sub-contexts, for example like this, if some “contained” id is not really an @id:

{
    "@context": {
        "@version": 1.1,
        ...
        "id": "@id",
        "something": {
            "@context": {
                "id": "id"

You could also consider using @propagate false in the context.