Reputation: 115
Is there a way to force single objects to an array? It is really annoying to test object type every time.
I tried this context, but it doesnt work. There is also example in JSON-LD Playground. With this context resources are turned into single objects and not array containing one object, as you would expect.
{
"@context": {
"member": {
"@id": "http://xmlns.com/foaf/0.1/member",
"@container": "@list"
},
"ex": "http://example.org/ex#",
"foaf": "http://xmlns.com/foaf/0.1/",
"owl": "http://www.w3.org/2002/07/owl#",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"frapo": "http://purl.org/cerif/frapo/"
},
"@type": "foaf:Organisation",
"member": []
}
Result:
... {
"@id": "ex:Organization_1",
"@type": "foaf:Organisation",
"foaf:member": {
"@id": "ex:Person_1",
"@type": "foaf:Person",
"foaf:name": "Bill"
}
} ...
And what it should be:
"foaf:member": [{ "@id": ... }]
Upvotes: 6
Views: 1815
Reputation: 2096
Use "@container": "@set"
instead of @list
.
@list
implies order -- and @set
does not. JFYI, it's possible that your "member" term is not being selected (by the algorithm) when compacting your data because your input does not match a @list
. If your data doesn't match a term in your context, an alternative term that does match (or the full url) will be used. In short, use @set
instead.
Upvotes: 0
Reputation: 3823
Compliant JSON-LD processors allow you to set a couple of options when processing JSON-LD: http://www.w3.org/TR/json-ld-api/#the-jsonldoptions-type
Just set the compactArrays
flag to false
.
Upvotes: 4