RE: Representation of an empty indexed collection

Hi,


On Tuesday, July 01, 2014 1:20 PM, Vagif Abilov wrote:
> We have a small issue with serializing as JSON-LD a document that
> contain an indexed collection in case the collection is empty but we
> would the element to be part of the document.
> 
> This is our context definition:
> 
>     "@context": {
>       "@base": "http://mabridge01/",
>       "bridge": "https://confluence.nrk.no/display/RED/Ordbok#",
>       "schema": "http://schema.org/",
>       "jobId": "bridge:jobId",
>       "data": {
>         "@id": "bridge:data",
>         "@container": "@index"
>       }
>     }
> 
[...]
> Here's an example with an empty collection:
> 
> {
>   "@id": "http://mabridge01/api/v1/systems/bridge/jobs/statuses/123",
>   "jobId": "123",
>   "data": {}
>   }
> 
> Resulting compacted JSON-LD (with context removed):
> 
> {
>   "@id": "api/v1/systems/bridge/jobs/statuses/123",
>   "bridge:data": [],
>   "jobId": "123"
> }
> 
> As you see, as long as "data" element contains an empty object (or
> list, I also tried that), it is not serialized as a dictionary, i.e.
> an indexed collection. So there is no way to include in a document an
> empty container of a type @index (unless its value is set to "null"
> but then it will be removed from the resulting document). Is there a
> way to represent an empty indexed container?

Internally, compaction internally expands the document first. Then it looks for the term that matches the data best. In this case, data isn't the best match as the data doesn't contain any indexes, thus, the second best term, the compact IRI bridge:data, gets chosen. There's no way to work around this unless you ensure that the index-container is never empty. So, the simplest thing to do if you have to ensure that the data always has the same shape is to do a little bit of post-processing.



--
Markus Lanthaler
@markuslanthaler

Received on Tuesday, 1 July 2014 12:17:24 UTC