JSON-LD frame arrays of single objects

Is there a way to force individual objects to an array? It is actually very difficult to test the type of an object every time.

I tried this context, but it does not work. There is also an example in the JSON-LD Playground . Using this context, resources are turned into separate objects, and not into an array containing one object, as one 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 should it be:

 "foaf:member": [{ "@id": ... }] 
+5
source share
2 answers

Use "@container": "@set" instead of @list .

@list implies order - and @set does not. JFYI, it is possible that your term "member" will not be selected (according to the algorithm) when compressing your data, because your input does not match the value of @list . If your data does not match the term in your context, an alternative term will be used that matches (or the full URL). In short, use @set .

0
source

Compatible JSON-LD processors allow you to set several parameters when processing JSON-LD: http://www.w3.org/TR/json-ld-api/#the-jsonldoptions-type

Just set the compactArrays flag to false .

+3
source

All Articles