In JSON-LD, can I define a URI mapping for a property value?

Suppose we have the following JSON:

{ "@context": { "name": "http://schema.org/name", "status": "http://schema.org/status" }, "name": "Manu Sporny", "status": "trollin'" } 

( playground JSON-LD )

Say we have a URI for troll status: http://example.com/trolling .

Is it possible to map the trollin' keyword to a URI?

Something direct won't work:

 { "@context": { "name": "http://schema.org/name", "status": "http://schema.org/status", "trollin'": "http://example.com/trolling" }, "name": "Manu Sporny", "status": "trollin'" } 

( JSON Playground )

The forced status to @id type @id also not work, since it is assumed that trollin' is a relative URI.

 { "@context": { "name": "http://schema.org/name", "status": { "@id": "http://schema.org/status", "@type": "@id" }, "trollin'": "http://example.com/trolling" }, "name": "Manu Sporny", "status": "trollin'" } 

( playground JSON-LD )

+5
source share
1 answer

Yes, you can do this, you need to set the status type to @vocab:

 { "@context": { "name": "http://schema.org/name", "status": { "@id": "http://schema.org/status", "@type": "@vocab" }, "trollin'": "http://example.com/trolling" }, "name": "Manu Sporny", "status": "trollin'" } 

Here is a link to the playground.

+4
source

Source: https://habr.com/ru/post/1205788/


All Articles