AdamZ
AdamZ

Reputation: 2021

Json-ld defining type for node

I have a simple json file like:

{
   "name": "something"
}

Now I Have a json-ld definition where there are objects. There is object with id #something - it exists lets say on http://example.com/test.jsonld#something.

Now I want to add context without modyfying original data so Name becomes a type and value becomes IRI to http://example.com/test.jsonld#something.

I've done something like this:

{
   "@context":{
      "name":"@type"
   },
   "@id":"1234",
   "name":"something"
}

This gives me in jsonld playground almost what I want:

{
   "@id": "1234",
   "@type": "http://json-ld.org/playground/something",
}

How do I add context so value "something is expanded to IRI http://example.com/test.jsonld#something instead of playgorund ?

Tried with "@base" but it also changes the @id to url.

Upvotes: 2

Views: 523

Answers (1)

Markus Lanthaler
Markus Lanthaler

Reputation: 3823

You can use terms (strings mapped to IRIs) as values of @type. As you alias name to @type already, all you need to do is to add the mapping from something to http://example.com/test.jsonld#something:

{
  "@context":{
    "name": "@type",
    "something": "http://example.com/test.jsonld#something"
  },
  "@id": "1234",
  "name": "something"
}

Tried with "@base" but it also changes the @id to url.

The value of @id is always a IRI. It is just not expanded if you don't have a base ("@base": null)

Upvotes: 2

Related Questions