Skip to content

Commit b0addea

Browse files
committed
Add statement that keywords can't be aliased to other keywords, add test
This addresses the discussion in 51703b8. /cc @msporny
1 parent 3424169 commit b0addea

8 files changed

+68
-26
lines changed

spec/latest/json-ld-syntax/index.html

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,37 +2314,41 @@ <h2>Identifying Blank Nodes</h2>
23142314
</section>
23152315

23162316
<section>
2317-
<h2>Aliasing Keywords</h2>
2317+
<h2>Aliasing Keywords</h2>
23182318

2319-
<p>Each of the JSON-LD <tref title="keyword">keywords</tref>,
2320-
except for <code>@context</code>, may be aliased to application-specific
2321-
keywords. This feature allows legacy JSON content to be utilized
2322-
by JSON-LD by re-using JSON keys that already exist in legacy documents.
2323-
This feature also allows developers to design domain-specific implementations
2324-
using only the JSON-LD <tref>context</tref>.</p>
2319+
<p>Each of the JSON-LD <tref title="keyword">keywords</tref>,
2320+
except for <code>@context</code>, may be aliased to application-specific
2321+
keywords. This feature allows legacy JSON content to be utilized
2322+
by JSON-LD by re-using JSON keys that already exist in legacy documents.
2323+
This feature also allows developers to design domain-specific implementations
2324+
using only the JSON-LD <tref>context</tref>.</p>
23252325

2326-
<pre class="example" data-transform="updateExample"
2327-
title="Aliasing keywords">
2328-
<!--
2329-
{
2330-
"@context":
2326+
<pre class="example" data-transform="updateExample"
2327+
title="Aliasing keywords">
2328+
<!--
23312329
{
2332-
****"url": "@id"****,
2333-
****"a": "@type"****,
2334-
"name": "http://schema.org/name"
2335-
},
2336-
"****url****": "http://example.com/about#gregg",
2337-
"****a****": "http://schema.org/Person",
2338-
"name": "Gregg Kellogg"
2339-
}
2340-
-->
2341-
</pre>
2330+
"@context":
2331+
{
2332+
****"url": "@id"****,
2333+
****"a": "@type"****,
2334+
"name": "http://schema.org/name"
2335+
},
2336+
"****url****": "http://example.com/about#gregg",
2337+
"****a****": "http://schema.org/Person",
2338+
"name": "Gregg Kellogg"
2339+
}
2340+
-->
2341+
</pre>
23422342

2343-
<p>In the example above, the <code>@id</code> and <code>@type</code>
2344-
<tref title="keyword">keywords</tref> have been given the aliases <strong>url</strong> and
2345-
<strong>a</strong>, respectively.
2346-
</p>
2343+
<p>In the example above, the <code>@id</code> and <code>@type</code>
2344+
<tref title="keyword">keywords</tref> have been given the aliases
2345+
<strong>url</strong> and <strong>a</strong>, respectively.</p>
23472346

2347+
<p>Since keywords cannot be re-defined, they can also not be aliased to
2348+
other keywords. In fact, every statement in the context having a keyword
2349+
as the member name (as in
2350+
<code style="white-space: nowrap">{ "@type": ... }</code>) will be
2351+
completely ignored when being processed.</p>
23482352
</section>
23492353

23502354
<section>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"@context": {
3+
"@type": "@id"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{
3+
"@type": [ "http://example.org/type" ]
4+
}
5+
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@type": "@id"
4+
},
5+
"@type": "http://example.org/type"
6+
}

test-suite/tests/compact-manifest.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@
271271
"input": "compact-0044-in.jsonld",
272272
"context": "compact-0044-context.jsonld",
273273
"expect": "compact-0044-out.jsonld"
274+
}, {
275+
"@type": ["test:TestCase", "jld:CompactTest"],
276+
"name": "Keywords cannot be aliased to other keywords",
277+
"input": "compact-0045-in.jsonld",
278+
"context": "compact-0045-context.jsonld",
279+
"expect": "compact-0045-out.jsonld"
274280
}
275281
]
276282
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@type": "@id"
4+
},
5+
"@type": "http://example.org/type"
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{
3+
"@type": [ "http://example.org/type" ]
4+
}
5+
]

test-suite/tests/expand-manifest.jsonld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@
216216
"name": "Keep empty arrays when expanding property generators",
217217
"input": "expand-0042-in.jsonld",
218218
"expect": "expand-0042-out.jsonld"
219+
}, {
220+
"@type": ["test:TestCase", "jld:ExpandTest"],
221+
"name": "Keywords cannot be aliased to other keywords",
222+
"input": "expand-0043-in.jsonld",
223+
"expect": "expand-0043-out.jsonld"
219224
}
220225
]
221226
}

0 commit comments

Comments
 (0)