json-ld / json-ld.org

JSON for Linked Data's documentation and playground site
https://json-ld.org/
Other
856 stars 152 forks source link

Using framing to differentiate between types in a list. #707

Open Panaetius opened 4 years ago

Panaetius commented 4 years ago

We have software where an object has several properties that are lists but that all map to the same property in the ontology, namely schema:hasPart. This all gets turned into a single list on expansion, but we'd like to be able to reconstruct it using framing.

A more concrete example, there's a Project that can contain a list of pdf files and a list of spreadsheet files, all of which are hasPart of the Project in the linked data representation. So in triples it'd be a single list of parts, but in code/json it's multiple lists based on types.

What we'd like to see is that the input and frame here result in a json that has a pdfs and a files property as in the input, so that that part doesn't get lost during (or can be reconstructed after) expansion.

It works for a single property, for instance this example reconstructs pdfs and only puts the two files of type pdf in there, ignoring the one file of type spreadsheet (it's the same as the example above but with spreadsheets removed from the frame context).

Some parts of our software use expansion/compaction for mutating program data, but in cases where multiple properties in code map to the same property in jsonld, that information gets lost. It sounds like framing would allow to reconstruct the stucture without having to manually do it.

Unfortutantely, as soon as there's more than one property/list in the frame, it results in the jsonld.SyntaxError: Invalid JSON-LD syntax; a JSON-LD frame must be a single object. exception.

Is this something that's intented to be possible with jsonld framing? If so, what am I doing wrong in the examples? If not, is there another way this can be achieved?