I have the following JSON document (based on GitHub API output):
{
"@id": "https://github.com/octadocs/octadocs",
"license": {
"key": "mit",
"name": "MIT License",
"spdx_id": "MIT",
"url": "https://api.github.com/licenses/mit",
"node_id": "MDc6TGljZW5zZTEz"
}
}
Using JSON-LD, I'd like to retrieve the following triple from this:
<https://github.com/octadocs/octadocs>
<https://octadocs.io/github/license>
<https://spdx.org/licenses/MIT> .
license as https://octadocs.io/github/license with @vocab (I would like to use it globally actually, for all properties);@type for spdx_id to make its value an IRI;@context with a @base for it, to convert MIT string into an spdx.org reference.Context:
{
"@base": "https://octadocs.io/github/",
"@vocab": "https://octadocs.io/github/",
"spdx_id": {
"@type": "@id",
"@context": {
"@base": "https://spdx.org/licenses/"
}
}
}
See a demonstration in JSON-LD playground.
But, this creates a slightly different structure than the desired one:
<https://github.com/octadocs/octadocs> <https://octadocs.io/github/license> _:b0 .
_:b0 <https://octadocs.io/github/spdx_id> <https://spdx.org/licenses/MIT> .
I'd like to avoid the blank node.
This can be achieved by JSON-LD keyword aliasing:
{
...,
"spdx_id": "@id"
}
but how to simultaneously
@type and @context for it?What you want to do is remove the @vocab definition within license, alias spdx_id to @id, and remove the default vocabulary. This treats the object value of license as a node object (really node reference) as all keys other than spdx_id are ignored. See playground link here.
{
"@context": {
"@base": "https://octadocs.io/github/",
"@vocab": "https://octadocs.io/github/",
"license": {
"@context": {
"@vocab": null,
"spdx_id": "@id"
}
}
},
"@id": "https://github.com/octadocs/octadocs",
"license": {
"key": "mit",
"name": "MIT License",
"spdx_id": "MIT",
"url": "https://api.github.com/licenses/mit",
"node_id": "MDc6TGljZW5zZTEz"
}
}