1

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> .
  • I can interpret license as https://octadocs.io/github/license with @vocab (I would like to use it globally actually, for all properties);
  • I can specify @type for spdx_id to make its value an IRI;
  • and I finally can define a @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

  • alias the property,
  • and define things like @type and @context for it?

1 Answer 1

2

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"
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! I did not think to use nested @context here. But I am still a little bit puzzled. How could I specify that the @base for spdx_id (not for other keys in license block) is spdx.org/licenses? Otherwise, this key maps to octadocs.io/github/MIT.
After some thought... It seems okay to add "@base": "http://spdx.org/licenses/" to the nested context and it works, not causing any unwanted side effects. Thanks a lot again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.