Let @vocab take precedence over compact IRIs in compaction · Issue #235 · json-ld/json-ld.org (original) (raw)

If a @vocab mapping is given, compaction should use that to avoid creating a compact IRI for a term. The purpose of compaction is to make the results as simple and usable as possible, and consumption of JSON with CURIE terms is problematic and undesirable. I propose that @vocab is considered prior to making a compact IRI.

That means moving the content of step 6 before step 3 in 8.3 IRI Compaction of the Processing Algorithms. And to rewrite the initial text of that section to something like:

"If no term was found that could be used to compact the IRI, then an attempt is made to construct one based on the active context's vocabulary mapping, if there is one. If no such term can be constructed, then an attempt is made to find a compact IRI. If there is no appropriate compact IRI, the IRI is transformed to a relative IRI using the document's base IRI. Finally, if the IRI or keyword still could not be compacted, it is returned as is."

That would ensure that this data:

{ "@type": "http://schema.org/Document", "http://schema.org/name": "Something" }

when compacted with this context:

{ "@context": { "schema": "http://schema.org/", "@vocab": "http://schema.org/" } }

results in:

{ "@type": "Document", "name": "Something" }

(Of course, we must ensure that this has no unexpected consequences. It doesn't seem so, but the change should be verified with an implementation against the test suite.)