Skip to content

Commit ac0f26c

Browse files
#90 Compare JSON vs YAML
1 parent 9e6bc30 commit ac0f26c

File tree

1 file changed

+98
-17
lines changed

1 file changed

+98
-17
lines changed

spec/index.html

Lines changed: 98 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove" defer></script>
77
<script src="../common/common.js" class="remove" defer></script>
88
<script class='remove'>
9-
// Use fragment identifer of test as name.
9+
// Use fragment identifier of test as name.
1010
function data_test_display() {
1111
const test_references = document.querySelectorAll('details.respec-tests-details a');
1212
for( const a of test_references ) {
1313
const href = a.href;
1414
const test_reference = href.split('#')[1];
1515
a.textContent = test_reference;
16-
}
16+
}
1717
}
1818

1919
var respecConfig = {
@@ -533,21 +533,102 @@ <h2>Basic Concepts</h2>
533533
interoperability considerations.
534534
</p>
535535

536-
<p>
537-
This is because YAML is more flexible than [[JSON]]:
538-
</p>
536+
<section id="json-vs-yaml">
537+
<h3>JSON vs YAML comparison</h3>
539538

540-
<ul>
541-
<li>YAML supports different encodings, including UTF-8, UTF-16, and UTF-32.</li>
542-
<li>YAML supports more native data types than JSON.</li>
543-
<li>The structure of a <a>YAML document</a> &mdash; that is, a <a>YAML representation graph</a> &mdash;
544-
is a rooted, directed graph that can have cycles.</li>
545-
<li>YAML is serialized as a <a>YAML stream</a>, which is a sequence of <a>YAML documents</a>.
546-
While a stream often contains one document,
547-
streams with multiple documents are used to aggregate multiple,
548-
related, documents into a single file or network stream.
549-
</li>
550-
</ul>
539+
<p>YAML is more flexible than JSON, as illustrated by comparison table below.</p>
540+
541+
<table class="simple">
542+
<thead>
543+
<tr>
544+
<th>Features</th>
545+
<th>[[JSON]]</th>
546+
<th>[[YAML]]</th>
547+
</tr>
548+
</thead>
549+
<tbody>
550+
<tr>
551+
<th colspan="3">Allowed encodings</th>
552+
</tr>
553+
554+
<tr>
555+
<th>UTF-8</th>
556+
<td><a data-cite="JSON#section-8.1">✔️</a></td>
557+
<td><a data-cite="YAML#52-character-encodings">✔️</a></td>
558+
</tr>
559+
560+
<tr>
561+
<th>UTF-16</th>
562+
<td><a data-cite="JSON#section-8.1"></a></td>
563+
<td><a data-cite="YAML#52-character-encodings">✔️</a></td>
564+
</tr>
565+
566+
<tr>
567+
<th>UTF-32</th>
568+
<td><a data-cite="JSON#section-8.1"></a></td>
569+
<td><a data-cite="YAML#52-character-encodings">✔️</a></td>
570+
</tr>
571+
572+
<tr>
573+
<th colspan="3">Native data types</th>
574+
</tr>
575+
576+
<tr>
577+
<th><code>{}</code> object</th>
578+
<td><a data-cite="JSON#section-4">✔️</a></td>
579+
<td><a data-cite="YAML#3211-nodes">✔️</a></td>
580+
</tr>
581+
582+
<tr>
583+
<th><code>[]</code> array</th>
584+
<td><a data-cite="JSON#section-5">✔️</a></td>
585+
<td><a data-cite="YAML#3211-nodes">✔️</a></td>
586+
</tr>
587+
588+
<tr>
589+
<th>string</th>
590+
<td><a data-cite="JSON#section-7">✔️</a></td>
591+
<td><a data-cite="YAML#3211-nodes">✔️</a></td>
592+
</tr>
593+
594+
<tr>
595+
<th>number</th>
596+
<td><a data-cite="JSON#section-6">✔️</a></td>
597+
<td>✔️<a data-cite="YAML#10213-integer">integer</a> <a data-cite="YAML#10214-floating-point">floating
598+
point</a></td>
599+
</tr>
600+
601+
<tr>
602+
<th>bool</th>
603+
<td><a data-cite="JSON#section-3">✔️</a></td>
604+
<td><a data-cite="YAML#10212-boolean">✔️</a></td>
605+
</tr>
606+
607+
<tr>
608+
<th>null</th>
609+
<td><a data-cite="JSON#section-3">✔️</a></td>
610+
<td><a data-cite="YAML#10211-null">✔️</a></td>
611+
</tr>
612+
613+
<tr>
614+
<th>custom types</th>
615+
<td></td>
616+
<td>✔️ via <a data-cite="YAML#tags">tags</a></td>
617+
</tr>
618+
619+
<tr>
620+
<th>Cycles</th>
621+
<td></td>
622+
<td><a data-cite="YAML#321-representation-graph">✔️</a></td>
623+
</tr>
624+
<tr>
625+
<th>Documents per file</th>
626+
<td>1</td>
627+
<td>⩾ 1 via <a>YAML stream</a></td>
628+
</tr>
629+
</tbody>
630+
</table>
631+
</section>
551632

552633
<p>
553634
The first goal of this specification is to allow a <a>JSON-LD document</a> to be
@@ -1192,7 +1273,7 @@ <h2>Best Practices</h2>
11921273
<h2>Extended YAML-LD Profile</h2>
11931274

11941275
<p>
1195-
To take better advantage of the broader expressivity of YAML,
1276+
To take better advantage of the <a href="#json-vs-yaml">broader expressivity of YAML</a>,
11961277
this document also defines a means of extending the
11971278
<a>JSON-LD internal representation</a> to allow a more complete expression
11981279
of native data types within YAML-LD, and allows use of the complete

0 commit comments

Comments
 (0)