Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDFLib JSON-LD processor accepts object's as values to @type #1950

Open
aucampia opened this issue May 17, 2022 · 2 comments
Open

RDFLib JSON-LD processor accepts object's as values to @type #1950

aucampia opened this issue May 17, 2022 · 2 comments
Labels
bug Something isn't working format: JSON-LD Related to JSON-LD format.

Comments

@aucampia
Copy link
Member

Given the following JSON-LD content in a file cat test/data/variants/forward_slash.jsonld

{
  "@context": {
      "kb": "http://example.org/kb/",
      "owl": "http://www.w3.org/2002/07/owl#"
  },
  "@graph": {
      "@id": "kb:individual-a",
      "@type": {
          "@id": "http://example.org/ontology/core/MyClassA",
          "@type": "owl:Class"
      }
  }
}

RDFLib loads it and converts it:

$ pipx run --spec git+https://github.com/RDFLib/rdflib.git@master#egg=rdflib rdfpipe -i json-ld -o turtle test/data/variants/forward_slash.jsonld
⚠️  rdfpipe is already on your PATH and installed at /home/iwana/.local/bin/rdfpipe. Downloading and running anyway.
@prefix kb: <http://example.org/kb/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

kb:individual-a a <http://example.org/ontology/core/MyClassA> .

<http://example.org/ontology/core/MyClassA> a owl:Class .

riot and jsonld-cli however both reject the above:

$ riot --syntax JSONLD --output NTRIPLES test/data/variants/forward_slash.jsonld
11:54:56 ERROR riot            :: invalid type value: @type value must be a string or array of strings

$ npx jsonld expand test/data/variants/forward_slash.jsonld
jsonld.SyntaxError: Invalid JSON-LD syntax; "@type" value must a string, an array of strings, or an empty object.
    at api.validateTypeValue (/home/iwana/.npm-packages/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/util.js:189:11)
    at _expandObject (/home/iwana/.npm-packages/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/expand.js:481:7)
    at Object.api.expand (/home/iwana/.npm-packages/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/expand.js:227:3)
    at _expandObject (/home/iwana/.npm-packages/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/expand.js:675:29)
    at api.expand (/home/iwana/.npm-packages/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/expand.js:227:3)
    at /home/iwana/.npm-packages/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/jsonld.js:332:18
    at async Function.expand (/home/iwana/.npm-packages/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/util.js:460:16)
Error: {
  "name": "jsonld.SyntaxError",
  "details": {
    "code": "invalid type value",
    "value": {
      "@id": "http://example.org/ontology/core/MyClassA",
      "@type": "owl:Class"
    }
  }
}

And from the JSON-LD spec I can't see anything that indicates this should be allowed.

On the one hand we can say this is not a bug, because according to IETF RFC 1958

Be strict when sending and tolerant when receiving.
Implementations must follow specifications precisely when sending to
the network, and tolerate faulty input from the network. When in
doubt, discard faulty input silently, without returning an error
message unless this is required by the specification.

However, to me this is a bug, it is pushing the principle too far and more details of the potential harms that will (and possibly already has) result from this can be seen in The Harmful Consequences of the Robustness Principle

There is however the possibility that I misread the JSON-LD spec, and that it should be allowed, and that riot and jsonld-cli is wrong.

@aucampia aucampia added bug Something isn't working format: JSON-LD Related to JSON-LD format. labels May 17, 2022
@aucampia
Copy link
Member Author

More info about the processing algorithm for JSON LD is defined in https://www.w3.org/TR/json-ld-api/ and I also cant see anything that would suggests that @type can have an object as a value.

@ajnelson-nist
Copy link
Contributor

Ah, dear. This was me making a stylistic guess between OWL's inlined anonymous classes (e.g. as frequently occurs with owl:Restrictions) and JSON-LD Framing, which I hadn't reviewed in depth yet. I'm fine with avoiding adding buggy data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working format: JSON-LD Related to JSON-LD format.
Projects
None yet
Development

No branches or pull requests

2 participants