user6454026 user6454026 - 5 months ago 23
JSON Question

IRI Mapping and referencing in JSON-LD

I am trying to design an ontology using JSON-LD but i'm having trouble getting the syntax right. I looked at https://www.w3.org/TR/json-ld but couldn't find exactly the piece of information I am looking for, which is this: How to nest IRI's in the context, and how to reference them in the body?

{
"@context":{
"@base":"http://example.com/",
"instances":"base:instances",
"animals":"base:animals",
"plants":"base:plants"
},
"@graph":[
{
"@id": "instances:1",
"@type": "Plant",
"plants:numleaves": "8",
"plants:speciesname": "sunflower"
},
{
"@id": "instances:2",
"@type": "Animal",
"animals:numlegs": "4",
"animals:speciesname": "dog",
"animals:eats": "instances:1"
}
]
}


I want the id of the first element to be
http://example.com/instances#1
, but when I run it through http://json-ld.org/playground/ , it's expanded form is
base:instances1
. How do I make it right?

Answer

It doesn't work the way you want, because you define @base and then try to use it as a prefix.

Also the hash (#) won't just magically appear. You must include it in your base URI.

To sum up you would have to change your context to:

"@context":{
  "base":"http://example.com/",
  "instances":"base:instances#",
  "animals":"base:animals#",
  "plants":"base:plants#"
}

Now instances:1 is a concatenation of http://example.com/ + instances# + 1 as you ask for.