Skip to content

Commit 4928311

Browse files
authored
Merge pull request #27 from rubensworks/add/context-ordering
Add entry on context ordering
2 parents 661ed9b + 95efbc7 commit 4928311

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

index.html

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,70 @@ <h3 id="type-links">External references should use typed term</h3>
307307
}
308308
</pre>
309309
</section>
310+
311+
<section>
312+
<h3 id="context-order">Ordering of array elements</h3>
313+
<p class="practicedesc">By default, <a class="externalDFN" href="https://www.w3.org/TR/json-ld/#sets-and-lists">arrays in JSON-LD do not convey any ordering of contained elements</a>.
314+
However, for the processing of contexts, the ordering of elements in arrays <em>does</em> matter.
315+
As such, when writing array-based contexts, this fact should be kept in mind.</p>
316+
<p>Ordered contexts in arrays allow inheritance and overriding of context entries.
317+
When processing the following example, the first <code>name</code> entry will be overridden by the second <code>name</code> entry.</p>
318+
<pre class="example" title="Overriding name term">
319+
{
320+
"@context": [
321+
{
322+
"id": "@id",
323+
"name": "http://schema.org/name"
324+
},
325+
{
326+
"name": "http://xmlns.com/foaf/0.1/name"
327+
}
328+
],
329+
"@id": "http://www.wikidata.org/entity/Q76",
330+
<strong>"name": "Barack Obama"</strong>
331+
}
332+
</pre>
333+
<p>Order is important when processing <a class="externalDFN" href="https://www.w3.org/TR/json-ld/#protected-term-definitions">protected terms</a>.
334+
While the first example will cause a term redefinition error, the second example will not throw this error.</p>
335+
<pre class="example" title="Failing term redefinition">
336+
{
337+
"@context": [
338+
{
339+
"@version": 1.1,
340+
"name": {
341+
"@id": "http://schema.org/name",
342+
"@protected": true
343+
}
344+
},
345+
{
346+
"name": "http://xmlns.com/foaf/0.1/name"
347+
}
348+
],
349+
"@id": "http://www.wikidata.org/entity/Q76",
350+
<strong>"name": "Barack Obama"</strong>
351+
}
352+
</pre>
353+
<pre class="example" title="Non-failing term redefinition">
354+
{
355+
"@context": [
356+
{
357+
"name": "http://xmlns.com/foaf/0.1/name"
358+
},
359+
{
360+
"@version": 1.1,
361+
"Person": "http://schema.org/Person",
362+
"knows": "http://schema.org/knows",
363+
"name": {
364+
"@id": "http://schema.org/name",
365+
"@protected": true
366+
}
367+
}
368+
],
369+
"@id": "http://www.wikidata.org/entity/Q76",
370+
<strong>"name": "Barack Obama"</strong>
371+
}
372+
</pre>
373+
</section>
310374
</section>
311375

312376

0 commit comments

Comments
 (0)