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

JSON-LD serializer wrongly uses @type #182

Open
pchampin opened this issue Apr 21, 2024 · 0 comments
Open

JSON-LD serializer wrongly uses @type #182

pchampin opened this issue Apr 21, 2024 · 0 comments

Comments

@pchampin
Copy link
Contributor

Issue Description:

Sometimes, Corese produces invalid JSON-LD. More specifically, it uses @type with a value object as its value.

Steps to Reproduce:

Submit the following SPARQL query, requesting the result in application/ld+json:

CONSTRUCT { <tag:s> a 42 } {}

Expected Behavior:

The result should be (something like)

{
    "@context": {
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
        "xsd": "http://www.w3.org/2001/XMLSchema#"
    },
    "@graph": [
        {
            "@id": "tag:s",
            "rdf:type": {
                "@type": "xsd:integer",
                "@value": "42"
            }
        }
    ]
}

Actual Behavior:

The result is

{
    "@context": {
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
        "xsd": "http://www.w3.org/2001/XMLSchema#"
    },
    "@graph": [
        {
            "@id": "tag:s",
            "@type": {
                "@type": "xsd:integer",
                "@value": "42"
            }
        }
    ]
}

which is invalid.

Note to Developers:

When generating JSON-LD, when the predicate is rdf:type, the @type keyword must not be used if the object is a literal. Instead, the property key rdf:type should be used (provided that the context defines the rdf prefix -- otherwise, the whole IRI should be used as the property key).

Granted, literals as the object of rdf:type are a bit of a corner case, but they are valid RDF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant