JSON-LD serializer wrongly uses `@type`
pchampin opened this issue · 0 comments
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.