Closed rmeissn closed 4 years ago
Without altering i have no idea
{
"@context": {
"@version": 1.1,
"points": { "@id": "http://ex.org/points", "@type": "http://www.w3.org/2001/XMLSchema#short"},
"answers": { "@id": "http://ex.org/hasAnswer", "@container": "@set"},
"answerText": { "@id": "http://ex.org/hasAnswerText", "@type": "http://www.w3.org/2001/XMLSchema#short"},
"ex" : "http://ex.org/"
},
"@id": "http://ex.org/1",
"answers": [
{
"answerText": "Answer 1",
"points": 3,
"@type" : "ex:Answer"
},
{
"answerText": "Answer 2",
"points": 0,
"@type" : "ex:Answer"
}
]
}
It's better to bring up issues like this in the JSON-LD syntax spec issue tracker since it's an issue for other implementations too. This type of request has been brought up before in the CG and now the 1.1 WG. I think it was decided to not add this sort of functionality at this time. And more generally to not add features that add data during processing. Adding a @type
to everything in an array is the common use case, but if a feature like that exists it should probably handle more than just @type
. And pretty soon you have a feature design complexity issue. Feel free to bring this up, but it may not be addressed until a future spec. In the meantime you might look into your own custom processing step to add data.
Closing per @davidlehn's comments.
I've read most parts of https://w3c.github.io/json-ld-syntax/ and a lot on stackoverflow, but still have no idea how to add classes to a list of objects. Hence I have the following json:
and this context:
These resolve to:
which is correct. But I also want the result to contain:
like I tried to define in the context. So each answer object shall get the same class definition. I guess this is possible by using node type indexing, but it requires me to alter the json schema (which I don't want). Is there any way I achieve the desired result without altering the actual json (e.g. by a definition in the "@context")?