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
:
id: http://example.enola.dev/Picasso
type: http://example.enola.dev/Artist
firstName: Pablo
location: Spain
homeAddress:
city: Barcelona
street: 31 Art Gallery
---
id: http://example.enola.dev/Dalí
type: http://example.enola.dev/Artist
firstName: ["Salvador", "Domingo", "Felipe", "Jacinto"]
birthDate: "1904-05-11"
or from picasso.json
:
[
{
"@id": "http://example.enola.dev/Picasso",
"@type": "http://example.enola.dev/Artist",
"firstName": "Pablo",
"location": "Spain",
"homeAddress": { "city": "Barcelona", "street": "31 Art Gallery" }
},
{
"@id": "http://example.enola.dev/Dalí",
"@type": "http://example.enola.dev/Artist",
"firstName": ["Salvador", "Domingo", "Felipe", "Jacinto"],
"birthDate": "1904-05-11"
}
]
with a picasso-context.jsonld
:
{
"@context": {
"@version": 1.1,
"id": "@id",
"type": "@type",
"firstName": "http://xmlns.com/foaf/0.1/firstName",
"birthDate": {
"@id": "https://schema.org/birthDate",
"@type": "https://schema.org/Date"
},
"location": {
"@id": "http://www.w3.org/ns/locn#location",
"@language": "en"
},
"homeAddress": {
"@id": "http://example.enola.dev/homeAddress",
"@context": {
"city": "http://example.enola.dev/city",
"street": "http://example.enola.dev/street"
}
}
}
}
YAML to RDF Turtle 🐢¶
$ ./enola rosetta --in="test/picasso.yaml?context=test/picasso-context.jsonld" --out="fd:1?mediaType=text/turtle"
<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> [
<http://example.enola.dev/city> "Barcelona";
<http://example.enola.dev/street> "31 Art Gallery"
];
<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"
<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> [
<http://example.enola.dev/city> "Barcelona";
<http://example.enola.dev/street> "31 Art Gallery"
];
<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¶
String to Link¶
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.