-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.html
7182 lines (6757 loc) · 412 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<title>JSON-LD 1.1 Processing Algorithms and API</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="https://www.w3.org/Tools/respec/respec-w3c" class="remove"></script>
<script type="text/javascript" src="common/common.js" class="remove" defer></script>
<script type="text/javascript" src="common/jsonld.js" class="remove"></script>
<script type="text/javascript" class="remove">
//<![CDATA[
var respecConfig = {
// extend the bibliography entries
localBiblio: jsonld.localBiblio,
// specification status (e.g. WD, LCWD, NOTE, etc.). If in doubt use ED.
specStatus: "ED",
// if you wish the publication date to be other than today, set this
//publishDate: "2013-11-05",
copyrightStart: "2010",
// the specification's short name, as in http://www.w3.org/TR/short-name/
shortName: "json-ld11-api",
// if there is a previously published draft, uncomment this and set its YYYY-MM-DD date
// and its maturity status
prevVersion: "https://www.w3.org/TR/2020/PR-json-ld11-api-20200507/",
previousPublishDate: "2020-05-07",
previousMaturity: "PR",
prevRecURI: "https://www.w3.org/TR/2014/REC-json-ld-api-20140116/",
errata: "https://w3c.github.io/json-ld-api/errata/",
// if there a publicly available Editor's Draft, this is the link
edDraftURI: "https://w3c.github.io/json-ld-api/",
testSuiteURI: "https://w3c.github.io/json-ld-api/tests/",
implementationReportURI:"https://w3c.github.io/json-ld-api/reports/",
crEnd: "2020-04-03",
prEnd: "2020-06-18",
github: "https://github.com/w3c/json-ld-api",
// if you want to have extra CSS, append them to this list
// it is recommended that the respec.css stylesheet be kept
// extraCSS: [],
includePermalinks: true,
doJsonLd: true,
highlightVars: true,
pluralize: true,
// Cross-reference definitions
xref: ["json-ld11", "json-ld11-api", "json-ld11-framing"],
// editors, add as many as you like
// only "name" is required
editors: [
{ name: "Gregg Kellogg",
url: "https://greggkellogg.net/",
w3cid: "44770",
note: "v1.0 and v1.1" },
{ name: "Dave Longley",
url: "https://digitalbazaar.com/author/dlongley/",
w3cid: "48025",
company: "Digital Bazaar",
companyURL: "https://digitalbazaar.com/",
note: "v1.1" },
{ name: "Pierre-Antoine Champin",
url: "http://champin.net/",
company: "LIRIS - Université de Lyon",
companyURL: "https://liris.cnrs.fr/",
w3cid: "42931",
note: "v1.1" },
],
// editors, add as many as you like
// only "name" is required
formerEditors: [
{ name: "Markus Lanthaler",
url: "https://www.markus-lanthaler.com/",
company: "Google",
companyURL: "https://www.google.com/",
note: "v1.0" },
{ name: "Manu Sporny",
url: "http://manu.sporny.org/",
company: "Digital Bazaar",
companyURL: "https://digitalbazaar.com/",
note: "v1.0" }
],
// authors, add as many as you like.
// This is optional, uncomment if you have authors as well as editors.
// only "name" is required. Same format as editors.
authors: [
{ name: "Dave Longley",
url: "https://digitalbazaar.com/",
company: "Digital Bazaar",
companyURL: "https://digitalbazaar.com/",
note: "v1.0 and v1.1" },
{ name: "Gregg Kellogg",
url: "https://greggkellogg.net/",
w3cid: "44770",
note: "v1.0 and v1.1" },
{ name: "Markus Lanthaler",
url: "https://www.markus-lanthaler.com/",
company: "Google",
companyURL: "https://www.google.com/",
note: "v1.0" },
{ name: "Manu Sporny",
url: "http://manu.sporny.org/",
company: "Digital Bazaar",
companyURL: "https://digitalbazaar.com/",
note: "v1.0" },
{ name: "Niklas Lindström",
url: "http://neverspace.net/",
note: "v1.0" }
],
group: "wg/json-ld",
wgPublicList: "public-json-ld-wg",
maxTocLevel: 2,
alternateFormats: [ {uri: "json-ld11-api.epub", label: "EPUB"} ]
};
//]]>
</script>
<script>
document.addEventListener("DOMContentLoaded", () => {
// Add example button selection logic
for (const button of document.querySelectorAll(".ds-selector-tabs .selectors button")) {
button.onclick = () => {
const ex = button.closest(".ds-selector-tabs");
ex.querySelector("button.selected").classList.remove("selected");
ex.querySelector(".selected").classList.remove("selected");
button.classList.add('selected');
ex.querySelector("." + button.dataset.selects).classList.add("selected");
}
}
// Toggle show/hide changes
for (const elem of document.querySelectorAll(".show-changes")) {
elem.onclick = () => {
if (elem.classList.contains("selected")) {
// Remove highlight class from elements having "changed" class
elem.classList.remove("selected");
for (const changed of document.querySelectorAll(".changed")) {
changed.classList.remove("highlight");
}
} else {
// Add highlight class to elements having "changed" class
elem.classList.add("selected");
for (const changed of document.querySelectorAll(".changed")) {
changed.classList.add("highlight");
}
}
}
}
});
</script>
<style>
.hl-bold {font-weight: bold; color: #0a3;}
.comment {color: #999;}
.error a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
.example > pre.context:before {
content: "Context";
float: right;
font: x-large Arial, sans-serif;
color: gray;
border: solid thin black;
padding: 0.2em;
}
.example > pre.frame:before {
content: "Frame";
float: right;
font: x-large Arial, sans-serif;
color: gray;
border: solid thin black;
padding: 0.2em;
}
.example > pre.input:before {
content: "Input";
float: right;
font: x-large Arial, sans-serif;
color: gray;
border: solid thin black;
padding: 0.2em;
}
.example > pre.result:before {
content: "Result";
float: right;
font: x-large Arial, sans-serif;
color: gray;
border: solid thin black;
padding: 0.2em;
}
.example > pre.turtle:before {
content: "Turtle";
float: right;
font: x-large Arial, sans-serif;
color: gray;
border: solid thin black;
padding: 0.2em;
}
.algorithm ol {
counter-reset: numsection;
list-style-type: none;
}
.algorithm ol>li {
margin: 0.5em 0;
}
.algorithm ol>li:before {
font-weight: bold;
counter-increment: numsection;
content: counters(numsection, ".") ") ";
}
.highlight.changed, .show-changes {
background-color: lime;
}
.show-changes.selected:before {
content: "de-highlight";
}
.show-changes:before {
content: "highlight";
}
/* example tab selection */
.ds-selector-tabs {
padding-bottom: 2em;
}
.ds-selector-tabs .selectors {
padding: 0;
border-bottom: 1px solid #ccc;
height: 28px;
}
.ds-selector-tabs .selectors button {
display: inline-block;
min-width: 54px;
text-align: center;
font-size: 11px;
font-weight: bold;
height: 27px;
padding: 0 8px;
line-height: 27px;
transition: all,0.218s;
border-top-right-radius: 2px;
border-top-left-radius: 2px;
color: #666;
border: 1px solid transparent;
}
.ds-selector-tabs .selectors button:first-child {
margin-left: 2px;
}
.ds-selector-tabs .selectors button.selected {
color: #202020 !important;
border: 1px solid #ccc;
border-bottom: 1px solid #fff !important;
}
.ds-selector-tabs .selectors button:hover {
background-color: transparent;
color: #202020;
cursor: pointer;
}
.ds-selector-tabs pre:not(.preserve), .ds-selector-tabs table:not(.preserve) {
display: none;
}
.ds-selector-tabs pre.selected, .ds-selector-tabs table.selected {
display: block;
}
a.playground {
display: inline-block;
width: 150px;
border: 1px solid transparent;
border-top-right-radius: 2px;
border-top-left-radius: 2px;
background-color: rgb(192, 192, 192);
text-decoration: none;
font-size: 13px;
margin-bottom: 10px;
}
a[href].playground {
padding: 4px 0 3px 8px;
border-bottom: none;
text-decoration: none;
color: #666;
}
</style>
</head>
<body>
<section id="abstract">
<p>This specification defines a set of algorithms for programmatic transformations
of JSON-LD documents. Restructuring data according to the defined transformations
often dramatically simplifies its usage. Furthermore, this document proposes
an Application Programming Interface (API) for developers implementing the
specified algorithms.</p>
<p>This specification describes a superset of the features defined in
[[[JSON-LD10-API]]] [[JSON-LD10-API]]
and, except where noted,
the algorithms described in this specification are fully compatible
with documents created using [[[JSON-LD10]]] [[JSON-LD10]].</p>
</section>
<section id="sotd" class="updateable-rec">
<p>This document has been developed by the
<a href="https://www.w3.org/2018/json-ld-wg/">JSON-LD Working Group</a> and was derived from the <a href="https://www.w3.org/community/json-ld/">JSON-LD Community Group's</a> <a href="https://www.w3.org/2018/jsonld-cg-reports/json-ld-api/">Final Report</a>.</p>
<p>There is a
<a href="https://json-ld.org/playground/">live JSON-LD playground</a> that is capable
of demonstrating the features described in this document.</p>
<p>This specification is intended to <a href='https://www.w3.org/2019/Process-20190301/#rec-rescind'>supersede</a> the [[[JSON-LD10-API]]] [[JSON-LD10-API]] specification. </p>
<p class="correction">
This document includes <a href="#changes-from-rec1">Candidate Corrections</a> to the current
<a href="https://www.w3.org/TR/2020/REC-json-ld11-api-20200716/">W3C Recommendation dated 16 July 2020</a>.</p>
<section>
<h2>Set of Documents</h2>
<p>This document is one of three JSON-LD 1.1 Recommendations produced by the
<a href="https://www.w3.org/2018/json-ld-wg/">JSON-LD Working Group</a>:</p>
<ul>
<li>[[[JSON-LD11]]]</li>
<li><a href="">JSON-LD 1.1 Processing Algorithms and API</a></li>
<li>[[[JSON-LD11-FRAMING]]]</li>
</ul>
</section>
</section>
<section class="informative">
<h1>Introduction</h1>
<p>This document is a detailed specification of the JSON-LD processing algorithms.
The document is primarily intended for the following audiences:</p>
<ul>
<li>Software developers who want to implement the algorithms to transform
JSON-LD documents.</li>
<li>Web authors and developers who want a very detailed view of how
a <a>JSON-LD Processor</a> operates.</li>
<li>Developers who want an overview of the proposed JSON-LD API.</li>
</ul>
<p>To understand the basics in this specification you must first be familiar with
<a data-cite="RFC8259" data-no-xref="">JSON</a>, which is detailed in [[RFC8259]]. You must also understand the
JSON-LD syntax defined in the <a data-cite="JSON-LD11" data-no-xref="">JSON-LD 1.1 Syntax specification</a> [[JSON-LD11]], which is the base syntax used by all
of the algorithms in this document. To understand the API and how it is
intended to operate in a programming environment, it is useful to have working
knowledge of the JavaScript programming language [[ECMASCRIPT]] and
WebIDL [[WEBIDL]]. To understand how JSON-LD maps to RDF, it is helpful to be
familiar with the basic RDF concepts [[RDF11-CONCEPTS]].</p>
<section class="informative">
<h2>How to Read this Document</h2>
<p>This document is a detailed specification for a serialization of Linked
Data in JSON. The document is primarily intended for the following audiences:</p>
<ul>
<li>Software developers who want to implement processors and APIs for
JSON-LD</li>
</ul>
<p>A companion document, the JSON-LD 1.1 specification
[[JSON-LD11]], specifies the grammar of JSON-LD documents.</p>
<p>To understand the basics in this specification you must first be familiar with
<a data-cite="RFC8259" data-no-xref="">JSON</a>, which is detailed in [[RFC8259]].</p>
<p>This document can highlight changes since the [[[JSON-LD10]]] version.
Select to <button class="show-changes"></button> changes.</p>
</section>
<section class="informative">
<h2>Contributing</h2>
<p>There are a number of ways that one may participate in the development of
this specification:</p>
<ul>
<li>Technical discussion typically occurs on the public mailing list:
<a href="https://lists.w3.org/Archives/Public/public-json-ld-wg/">[email protected]</a></li>
<li>The working group uses <a href="https://irc.w3.org/?channels=json-ld">#json-ld</a>
IRC channel is available for real-time discussion on <a href="https://irc.w3.org">irc.w3.org</a>.</li>
<li>The <a href="https://webchat.freenode.net/?channels=json-ld">#json-ld</a>
IRC channel is also available for real-time discussion on irc.freenode.net.</li>
</ul>
</section>
<section class="informative">
<h2>Typographical conventions</h2>
<div data-include="common/typographical-conventions.html"></div>
</section>
<section class="normative">
<h2>Terminology</h2>
<p>This document uses the following terms as defined in external specifications
and defines terms specific to JSON-LD.</p>
<div data-include="common/terms.html"></div>
<section>
<h4>Algorithm Terms</h4>
<p>The Following terms are used within specific algorithms.</p>
<div data-include="common/algorithm-terms.html"></div>
</section>
<section id="api-keywords">
<h2>Syntax Tokens and Keywords</h2>
<p>In addition to the <a>keywords</a> defined in the JSON-LD 1.1 Syntax specification [[JSON-LD11]],
this specification adds an additional <a>keyword</a> to support
[[[JSON-LD11-FRAMING]]] [[JSON-LD11-FRAMING]]:</p>
<dl data-sort>
<dt><code>@preserve</code></dt>
<dd>Used in an expanded document created as the result of the
<a data-cite="JSON-LD11-FRAMING#framing-algorithm">Framing algorithm</a>
to represent values that might otherwise be removed as part of the
<a href="#expansion-algorithm">Expansion algorithm</a>.</dd>
</dl>
</section>
</section>
<section class="informative">
<h3>Example Conventions</h3>
<p>Note that in the examples used in this document, output
is of necessity shown in serialized form as JSON. While the algorithms
describe operations on the <a>JSON-LD internal representation</a>, when
they as displayed as examples, the JSON serialization is used. In particular,
the internal representation use of <a>maps</a> are represented using
<a>JSON objects</a>.</p>
<pre class="example nohighlight input" data-transform="updateExample"
title="Sample JSON-LD document">
<!--
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"knows": "http://xmlns.com/foaf/0.1/knows"
},
"@id": "http://me.markus-lanthaler.com/",
"name": "Markus Lanthaler",
"knows": [
{
"name": "Dave Longley"
}
]
}
-->
</pre>
<p>In the <a>internal representation</a>, the example above would be of a
<a>map</a> containing <code>@context</code>, <code>@id</code>, <code>name</code>, and <code>knows</code> <a>entries</a>,
with either <a>maps</a>, <a>strings</a>, or <a>arrays</a> of
maps or strings values. In the JSON serialization, <a>JSON objects</a> are used
for maps, while arrays and strings are serialized using a
convention common to many programming languages.</p>
</section>
</section> <!-- end of Introduction -->
<section class="informative">
<h1>Features</h1>
<p>The JSON-LD 1.1 Syntax specification [[JSON-LD11]] defines a syntax to
express Linked Data in JSON. Because there is more than one way to
express Linked Data using this syntax, it is often useful to be able to
transform JSON-LD documents so that they may be more easily consumed by
specific applications.</p>
<p class="changed">To allow these algorithms to be adapted for syntaxes
other than JSON, the algorithms operate on the <a>JSON-LD internal representation</a>,
which uses the generic
concepts of <a>arrays</a>, <a>maps</a>,
<a>strings</a>, <a>numbers</a>, <a>booleans</a>, and <a>null</a> to describe
the data represented by a JSON document. Algorithms act on this
<a>internal representation</a> with API entry points responsible for
transforming between the concrete and internal representations.</p>
<p>JSON-LD uses <a>contexts</a> to allow Linked Data
to be expressed in a way that is specifically tailored to a particular
person or application. By providing a <a>context</a>,
JSON data can be expressed in a way that is a natural fit for a particular
person or application whilst also indicating how the data should be
understood at a global scale. In order for people or applications to
share data that was created using a <a>context</a> that is different
from their own, a JSON-LD processor must be able to transform a document
from one <a>context</a> to another. Instead of requiring JSON-LD
processors to write specific code for every imaginable
<a>context</a> switching scenario, it is much easier to specify a
single algorithm that can remove any <a>context</a>. Similarly,
another algorithm can be specified to subsequently apply any
<a>context</a>. These two algorithms represent the most basic
transformations of JSON-LD documents. They are referred to as
<a>expansion</a> and <a>compaction</a>, respectively.</p>
<p class="changed">JSON-LD 1.1 introduces new features that are
compatible with [[[JSON-LD10]]] [[JSON-LD10]],
but if processed by a JSON-LD 1.0 processor may produce different results.
Processors default to `json-ld-1.1`, unless the
<a data-link-for="JsonLdOptions">processingMode</a> API option
is explicitly set to `json-ld-1.0`.
Publishers are encouraged to use the <code>@version</code> <a>map entry</a> within a <a>context</a>
set to `1.1` to ensure that JSON-LD 1.0 processors will not misinterpret JSON-LD 1.1 features.</p>
<p>There are four major types of transformation that are discussed in this
document: expansion, compaction, flattening, and RDF serialization/deserialization.</p>
<section class="informative">
<h2>Expansion</h2>
<p>The algorithm that removes <a>context</a> is
called <dfn data-lt="expanded|expanding">expansion</dfn>. Before performing any other
transformations on a JSON-LD document, it is easiest to
remove any <a>context</a> from it and to make data structures
more regular.</p>
<p>To get an idea of how context and data structuring affects the same data,
here is an example of JSON-LD that uses only <a>terms</a>
and is fairly compact:</p>
<aside class="example ds-selector-tabs"
title="JSON-LD document using only terms">
<div class="selectors">
<button class="selected input" data-selects="compacted">Compacted (Input)</button>
<button data-selects="expanded">Expanded (Result)</button>
<button data-selects="statements">Statements</button>
<button data-selects="turtle">Turtle</button>
<a class="playground" target="_blank" href="">PG</a>
</div>
<pre class="compacted selected" data-transform="updateExample">
<!--
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"homepage": {
"@id": "http://xmlns.com/foaf/0.1/homepage",
"@type": "@id"
}
},
"@id": "http://me.markus-lanthaler.com/",
"name": "Markus Lanthaler",
"homepage": "http://www.markus-lanthaler.com/"
}
-->
</pre>
<pre class="expanded result"
data-result-for="JSON-LD document using only terms-compacted"
data-transform="updateExample">
<!--
[{
"@id": "http://me.markus-lanthaler.com/",
"http://xmlns.com/foaf/0.1/name": [
{"@value": "Markus Lanthaler"}
],
"http://xmlns.com/foaf/0.1/homepage": [
{"@id": "http://www.markus-lanthaler.com/"}
]
}]
-->
</pre>
<table class="statements"
data-result-for="JSON-LD document using only terms-expanded">
<thead><tr><th>Subject</th><th>Property</th><th>Value</th></tr></thead>
<tbody>
<tr><td>http://me.markus-lanthaler.com/</td><td>foaf:name</td><td>Markus Lanthaler</td></tr>
<tr><td>http://me.markus-lanthaler.com/</td><td>http://xmlns.com/foaf/0.1/homepage</td><td>http://www.markus-lanthaler.com/</td></tr>
</tbody>
</table>
<pre class="turtle"
data-content-type="text/turtle"
data-result-for="JSON-LD document using only terms-expanded"
data-transform="updateExample"
data-to-rdf>
<!--
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://me.markus-lanthaler.com/> foaf:name "Markus Lanthaler";
foaf:homepage <http://www.markus-lanthaler.com/> .
-->
</pre>
</aside>
<p>The next input example uses one <a>IRI</a> to express a <a>property</a>
and a <a>map</a> to encapsulate a value, but
leaves the rest of the information untouched.</p>
<aside class="example ds-selector-tabs"
title="Sample JSON-LD document using an IRI instead of a term to express a property">
<div class="selectors">
<button class="selected input" data-selects="compacted">Compacted (Input)</button>
<button data-selects="expanded">Expanded (Result)</button>
<button data-selects="statements">Statements</button>
<button data-selects="turtle">Turtle</button>
<a class="playground" target="_blank" href="">PG</a>
</div>
<pre class="compacted input selected nohighlight" data-transform="updateExample">
<!--
{
"@context": {
****"website": "http://xmlns.com/foaf/0.1/homepage"****
},
"@id": "http://me.markus-lanthaler.com/",
"****http://xmlns.com/foaf/0.1/name****": "Markus Lanthaler",
****"website"****: ****{ "@id":**** "http://www.markus-lanthaler.com/" ****}****
}
-->
</pre>
<pre class="expanded result"
data-result-for="Sample JSON-LD document using an IRI instead of a term to express a property-compacted"
data-transform="updateExample">
<!--
[{
"@id": "http://me.markus-lanthaler.com/",
"http://xmlns.com/foaf/0.1/name": [
{"@value": "Markus Lanthaler"}
],
"http://xmlns.com/foaf/0.1/homepage": [
{"@id": "http://www.markus-lanthaler.com/"}
]
}]
-->
</pre>
<table class="statements"
data-result-for="Sample JSON-LD document using an IRI instead of a term to express a property-expanded">
<thead><tr><th>Subject</th><th>Property</th><th>Value</th></tr></thead>
<tbody>
<tr><td>http://me.markus-lanthaler.com/</td><td>foaf:name</td><td>Markus Lanthaler</td></tr>
<tr><td>http://me.markus-lanthaler.com/</td><td>http://xmlns.com/foaf/0.1/homepage</td><td>http://www.markus-lanthaler.com/</td></tr>
</tbody>
</table>
<pre class="turtle"
data-content-type="text/turtle"
data-result-for="Sample JSON-LD document using an IRI instead of a term to express a property-expanded"
data-transform="updateExample"
data-to-rdf>
<!--
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://me.markus-lanthaler.com/> foaf:name "Markus Lanthaler";
foaf:homepage <http://www.markus-lanthaler.com/> .
-->
</pre>
</aside>
<p>Note that both inputs are valid JSON-LD and both represent the same
information. The difference is in their <a>context</a> information
and in the data structures used. A JSON-LD processor can remove
<a>context</a> and ensure that the data is more regular by employing
<a>expansion</a>.</p>
<p><a>Expansion</a> has two important goals: removing any contextual
information from the document, and ensuring all values are represented
in a regular form. These goals are accomplished by expanding all <a>entry</a> keys
to <a>IRIs</a> and by expressing all
values in <a>arrays</a> in
<a>expanded form</a>. <a>Expanded form</a> is the most verbose
and regular way of expressing of values in JSON-LD; all contextual
information from the document is instead stored locally with each value.
Running the <a href="#expansion-algorithm">Expansion algorithm</a>
(<a data-link-for="JsonLdProcessor">expand()</a>)
operation) against the above examples results in the following output:</p>
<pre class="example result nohighlight" data-transform="updateExample"
data-result-for="Sample JSON-LD document using an IRI instead of a term to express a property-compacted"
title="Expanded JSON-LD document using an IRI">
<!--
[
{
"@id": "http://me.markus-lanthaler.com/",
"****http://xmlns.com/foaf/0.1/name****": [
{ "@value": "Markus Lanthaler" }
],
"****http://xmlns.com/foaf/0.1/homepage****": [
{ "@id": "http://www.markus-lanthaler.com/" }
]
}
]
-->
</pre>
<p class="changed">The example above is the JSON-LD serialization of the output of the
<a href="#expansion-algorithm">expansion algorithm</a>,
where the algorithm's use of <a>maps</a> are replaced with <a>JSON objects</a>.</p>
<p>Note that in the output above all <a>context</a> definitions have
been removed, all <a>terms</a> and
<a>compact IRIs</a> have been expanded to absolute
<a>IRIs</a>, and all
<a>JSON-LD values</a> are expressed in
<a>arrays</a> in <a>expanded form</a>. While the
output is more verbose and difficult for a human to read, it establishes a
baseline that makes JSON-LD processing easier because of its very regular
structure.</p>
</section> <!-- end of Expansion -->
<section class="informative">
<h2>Compaction</h2>
<p>While <a>expansion</a> removes <a>context</a> from a given
input, <dfn data-lt="compact|compacting|compacted|compacts">compaction</dfn>'s primary function is to
perform the opposite operation: to express a given input according to
a particular <a>context</a>. <a>Compaction</a> applies a
<a>context</a> that specifically tailors the way information is
expressed for a particular person or application. This simplifies applications
that consume JSON or JSON-LD by expressing the data in application-specific
terms, and it makes the data easier to read by humans.</p>
<p><a>Compaction</a> uses a developer-supplied <a>context</a> to
shorten <a>IRIs</a> to <a>terms</a> or
<a>compact IRIs</a> and
<a>JSON-LD values</a> expressed in
<a>expanded form</a> to simple values such as <a>strings</a>
or <a>numbers</a>.</p>
<p>For example, assume the following expanded JSON-LD input document:</p>
<pre id="sample-document"
class="example expanded input nohighlight" data-transform="updateExample"
title="Expanded sample document">
<!--
[
{
"@id": "http://me.markus-lanthaler.com/",
"http://xmlns.com/foaf/0.1/name": [
{ "@value": "Markus Lanthaler" }
],
"http://xmlns.com/foaf/0.1/homepage": [
{ "@id": "http://www.markus-lanthaler.com/" }
]
}
]
-->
</pre>
<p>Additionally, assume the following developer-supplied JSON-LD
<a>context</a>:</p>
<pre id="sample-document-context"
class="example context nohighlight"
data-transform="updateExample"
data-context-for="Expanded sample document"
title="JSON-LD context">
<!--
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"homepage": {
"@id": "http://xmlns.com/foaf/0.1/homepage",
"@type": "@id"
}
}
}
-->
</pre>
<p>Running the <a href="#compaction-algorithm">Compaction Algorithm</a>
(<a data-link-for="JsonLdProcessor">compact()</a>)
operation) given the context supplied above against the JSON-LD input
document provided above would result in the following output:</p>
<aside class="example ds-selector-tabs"
title="Compacted sample document">
<div class="selectors">
<a class="playground"
data-result-for="#sample-document"
data-context="#sample-document-context"
data-compact
target="_blank"
href="">PG</a>
</div>
<pre class="result compacted selected nohighlight" data-transform="updateExample"
data-result-for="Expanded sample document"
data-context="JSON-LD context"
data-compact
title="Compacted sample document">
<!--
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"homepage": {
"@id": "http://xmlns.com/foaf/0.1/homepage",
"@type": "@id"
}
},
"@id": "http://me.markus-lanthaler.com/",
"name": "Markus Lanthaler",
"homepage": "http://www.markus-lanthaler.com/"
}
-->
</pre>
</aside>
<p class="changed">The example above is the JSON-LD serialization of the output of the
<a href="#compaction-algorithm">compaction algorithm</a>,
where the algorithm's use of <a>maps</a> are replaced with <a>JSON objects</a>.</p>
<p>Note that all <a>IRIs</a> have been compacted to
<a>terms</a> as specified in the <a>context</a>,
which has been injected into the output. While compacted output is
useful to humans, it is also used to generate structures that are easy to
program against. Compaction enables developers to map any expanded document
into an application-specific compacted document. While the context provided
above mapped <code>http://xmlns.com/foaf/0.1/name</code> to <code>name</code>, it
could also have been mapped to any other term provided by the developer.</p>
</section> <!-- end of Compaction -->
<section class="informative">
<h2>Flattening</h2>
<p>While expansion ensures that a document is in a uniform structure,
<dfn data-lt="flattened" class="lint-ignore">flattening</dfn> goes a step further to ensure that the shape of the data
is deterministic. In expanded documents, the <a>properties</a> of a single
<a>node</a> may be spread across a number of different
<a class="changed">node objects</a>. By flattening a
document, all <a>properties</a> of a <a>node</a> are collected in a single
<a class="changed">node object</a> and all <a>blank nodes</a>
are labeled with a <a>blank node identifier</a>. This may drastically
simplify the code required to process JSON-LD data in certain applications.</p>
<p>For example, assume the following JSON-LD input document:</p>
<pre id="json-ld-document-in-compact-form"
class="example compacted input nohighlight" data-transform="updateExample"
title="JSON-LD document in compact form">
<!--
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"knows": "http://xmlns.com/foaf/0.1/knows"
},
"@id": "http://me.markus-lanthaler.com/",
"name": "Markus Lanthaler",
"knows": [
{"name": "Dave Longley"}
]
}
-->
</pre>
<p>Running the <a href="#flattening-algorithm">Flattening Algorithm</a>
(<a data-link-for="JsonLdProcessor">flatten()</a>)
operation) with a context set to <a>null</a> to prevent compaction
returns the following document:</p>
<aside class="example ds-selector-tabs"
title="Flattened sample document">
<div class="selectors">
<a class="playground"
data-result-for="#json-ld-document-in-compact-form"
data-flatten
target="_blank"
href="">PG</a>
</div>
<pre class="original result selected nohighlight" data-transform="updateExample"
data-result-for="JSON-LD document in compact form"
data-flatten>
<!--
[{
"@id": "http://me.markus-lanthaler.com/",
"http://xmlns.com/foaf/0.1/name": [
{ "@value": "Markus Lanthaler" }
],
"http://xmlns.com/foaf/0.1/knows": [
{ "@id": "_:b0" }
]
}, {
"@id": "_:b0",
"http://xmlns.com/foaf/0.1/name": [
{ "@value": "Dave Longley" }
]
}]
-->
</pre>
</aside>
<p class="changed">The example above is the JSON-LD serialization of the output of the
<a href="#flattening-algorithm">flattening algorithm</a>,
where the algorithm's use of <a>maps</a> are replaced with <a>JSON objects</a>.</p>
<p>Note how in the output above all <a>properties</a> of a <a>node</a> are collected in a
single <a class="changed">node object</a> and how the <a>blank node</a> representing
"Dave Longley" has been assigned the <a>blank node identifier</a>
<code>_:b0</code>.</p>
<p>To make it easier for humans to read or for certain applications to
process it, a flattened document can be compacted by passing a <a>context</a>. Using
the same context as the input document, the flattened and compacted document
looks as follows:</p>
<aside class="example ds-selector-tabs"
title="Flattened and compacted sample document">
<div class="selectors">
<a class="playground"
data-result-for="#json-ld-document-in-compact-form"
data-context="#json-ld-document-in-compact-form"
data-flatten
target="_blank"
href="">PG</a>
</div>
<pre class="result selected nohighlight" data-transform="updateExample"
data-result-for="JSON-LD document in compact form"
data-context="JSON-LD document in compact form"
data-flatten
title="Flattened and compacted sample document">
<!--
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"knows": "http://xmlns.com/foaf/0.1/knows"
},
"@graph": [{
"@id": "http://me.markus-lanthaler.com/",
"name": "Markus Lanthaler",
"knows": { "@id": "_:b0" }
}, {
"@id": "_:b0",
"name": "Dave Longley"
}]
}
-->
</pre>
</aside>
<p>Please note that the result of flattening and <a>compacting</a> a document
is always a <a class="changed">map</a>,
<span class="changed">(represented as a <a>JSON object</a> when serialized)</span>,
which contains an <code>@graph</code>
<a>entry</a> that represents the <a>default graph</a>.</p>
</section> <!-- end of Flattening -->
<section class="informative">
<h2>RDF Serialization/Deserialization</h2>
<p>JSON-LD can be used to serialize RDF data as described in
[[RDF11-CONCEPTS]]. This ensures that data can be round-tripped to and from
any RDF syntax without any loss in fidelity.</p>
<p>For example, assume the following RDF input serialized in Turtle [[TURTLE]]:</p>
<pre class="example nohighlight" data-transform="updateExample"
data-content-type="text/turtle"
data-from-rdf
title="Sample Turtle document">
<!--
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://me.markus-lanthaler.com/>
foaf:name "Markus Lanthaler" ;
foaf:homepage <http://www.markus-lanthaler.com/> .
-->
</pre>
<p>Using the <a href="#serialize-rdf-as-json-ld-algorithm">Serialize RDF as JSON-LD Algorithm</a>
a developer could transform this document into expanded JSON-LD:</p>
<pre class="example nohighlight" data-transform="updateExample"
data-result-for="Sample Turtle document"
data-from-rdf
title="Sample Turtle document converted to JSON-LD">
<!--
[
{
"@id": "http://me.markus-lanthaler.com/",
"http://xmlns.com/foaf/0.1/name": [
{ "@value": "Markus Lanthaler" }
],
"http://xmlns.com/foaf/0.1/homepage": [
{ "@id": "http://www.markus-lanthaler.com/" }
]
}
]
-->
</pre>
<p class="changed">The example above is the JSON-LD serialization of the output of the
<a href="#serialize-rdf-as-json-ld-algorithm">Serialize RDF as JSON-LD Algorithm</a>,
where the algorithm's use of <a>maps</a> are replaced with <a>JSON objects</a>.</p>
<p>Note that the output above could easily be compacted using the technique outlined
in the previous section. It is also possible to deserialize the JSON-LD document back
to RDF using the <a href="#deserialize-json-ld-to-rdf-algorithm">Deserialize JSON-LD to RDF Algorithm</a>.</p>
</section> <!-- end of RDF Serialization/Deserialization -->
</section> <!-- end of Features section -->
<section id="conformance">
<p>There are two classes of products that can claim conformance to this
specification: <a>JSON-LD Processors</a>,
and <a>RDF Serializers/Deserializers</a>.</p>