-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrfc.html
1019 lines (921 loc) · 39.8 KB
/
rfc.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 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head profile="http://www.w3.org/2006/03/hcard http://dublincore.org/documents/2008/08/04/dc-html/">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<title>The Human JSON (Hjson) Configuration Format</title>
<style type="text/css" title="Xml2Rfc (sans serif)">
/*<![CDATA[*/
a {
text-decoration: none;
}
/* info code from SantaKlauss at http://www.madaboutstyle.com/tooltip2.html */
a.info {
/* This is the key. */
position: relative;
z-index: 24;
text-decoration: none;
}
a.info:hover {
z-index: 25;
color: #FFF; background-color: #900;
}
a.info span { display: none; }
a.info:hover span.info {
/* The span will display just on :hover state. */
display: block;
position: absolute;
font-size: smaller;
top: 2em; left: -5em; width: 15em;
padding: 2px; border: 1px solid #333;
color: #900; background-color: #EEE;
text-align: left;
}
a.smpl {
color: black;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
address {
margin-top: 1em;
margin-left: 2em;
font-style: normal;
}
body {
color: black;
font-family: verdana, helvetica, arial, sans-serif;
font-size: 10pt;
max-width: 55em;
}
cite {
font-style: normal;
}
dd {
margin-right: 2em;
}
dl {
margin-left: 2em;
}
ul.empty {
list-style-type: none;
}
ul.empty li {
margin-top: .5em;
}
dl p {
margin-left: 0em;
}
dt {
margin-top: .5em;
}
h1 {
font-size: 14pt;
line-height: 21pt;
page-break-after: avoid;
}
h1.np {
page-break-before: always;
}
h1 a {
color: #333333;
}
h2 {
font-size: 12pt;
line-height: 15pt;
page-break-after: avoid;
}
h3, h4, h5, h6 {
font-size: 10pt;
page-break-after: avoid;
}
h2 a, h3 a, h4 a, h5 a, h6 a {
color: black;
}
img {
margin-left: 3em;
}
li {
margin-left: 2em;
margin-right: 2em;
}
ol {
margin-left: 2em;
margin-right: 2em;
}
ol p {
margin-left: 0em;
}
p {
margin-left: 2em;
margin-right: 2em;
}
pre {
margin-left: 3em;
background-color: lightyellow;
padding: .25em;
}
pre.text2 {
border-style: dotted;
border-width: 1px;
background-color: #f0f0f0;
width: 69em;
}
pre.inline {
background-color: white;
padding: 0em;
}
pre.text {
border-style: dotted;
border-width: 1px;
background-color: #f8f8f8;
width: 69em;
}
pre.drawing {
border-style: solid;
border-width: 1px;
background-color: #f8f8f8;
padding: 2em;
}
table {
margin-left: 2em;
}
table.tt {
vertical-align: top;
}
table.full {
border-style: outset;
border-width: 1px;
}
table.headers {
border-style: outset;
border-width: 1px;
}
table.tt td {
vertical-align: top;
}
table.full td {
border-style: inset;
border-width: 1px;
}
table.tt th {
vertical-align: top;
}
table.full th {
border-style: inset;
border-width: 1px;
}
table.headers th {
border-style: none none inset none;
border-width: 1px;
}
table.left {
margin-right: auto;
}
table.right {
margin-left: auto;
}
table.center {
margin-left: auto;
margin-right: auto;
}
caption {
caption-side: bottom;
font-weight: bold;
font-size: 9pt;
margin-top: .5em;
}
table.header {
border-spacing: 1px;
width: 95%;
font-size: 10pt;
color: white;
}
td.top {
vertical-align: top;
}
td.topnowrap {
vertical-align: top;
white-space: nowrap;
}
table.header td {
background-color: gray;
width: 50%;
}
table.header a {
color: white;
}
td.reference {
vertical-align: top;
white-space: nowrap;
padding-right: 1em;
}
thead {
display:table-header-group;
}
ul.toc, ul.toc ul {
list-style: none;
margin-left: 1.5em;
margin-right: 0em;
padding-left: 0em;
}
ul.toc li {
line-height: 150%;
font-weight: bold;
font-size: 10pt;
margin-left: 0em;
margin-right: 0em;
}
ul.toc li li {
line-height: normal;
font-weight: normal;
font-size: 9pt;
margin-left: 0em;
margin-right: 0em;
}
li.excluded {
font-size: 0pt;
}
ul p {
margin-left: 0em;
}
.comment {
background-color: yellow;
}
.center {
text-align: center;
}
.error {
color: red;
font-style: italic;
font-weight: bold;
}
.figure {
font-weight: bold;
text-align: center;
font-size: 9pt;
}
.filename {
color: #333333;
font-weight: bold;
font-size: 12pt;
line-height: 21pt;
text-align: center;
}
.fn {
font-weight: bold;
}
.hidden {
display: none;
}
.left {
text-align: left;
}
.right {
text-align: right;
}
.title {
color: #990000;
font-size: 18pt;
line-height: 18pt;
font-weight: bold;
text-align: center;
margin-top: 36pt;
}
.vcardline {
display: block;
}
.warning {
font-size: 14pt;
background-color: yellow;
}
@media print {
.noprint {
display: none;
}
a {
color: black;
text-decoration: none;
}
table.header {
width: 90%;
}
td.header {
width: 50%;
color: black;
background-color: white;
vertical-align: top;
font-size: 12pt;
}
ul.toc a::after {
content: leader('.') target-counter(attr(href), page);
}
ul.ind li li a {
content: target-counter(attr(href), page);
}
.print2col {
column-count: 2;
-moz-column-count: 2;
column-fill: auto;
}
}
@page {
@top-left {
content: "Internet-Draft";
}
@top-right {
content: "December 2010";
}
@top-center {
content: "Abbreviated Title";
}
@bottom-left {
content: "Doe";
}
@bottom-center {
content: "Expires June 2011";
}
@bottom-right {
content: "[Page " counter(page) "]";
}
}
@page:first {
@top-left {
content: normal;
}
@top-right {
content: normal;
}
@top-center {
content: normal;
}
}
/*]]>*/
</style>
<link href="#rfc.toc" rel="Contents"/>
<link href="#rfc.section.1" rel="Chapter" title="1 Introduction"/>
<link href="#rfc.section.1.1" rel="Chapter" title="1.1 Syntax compared to JSON"/>
<link href="#rfc.section.1.2" rel="Chapter" title="1.2 Conventions Used in This Document"/>
<link href="#rfc.section.1.3" rel="Chapter" title="1.3 Specifications of Hjson"/>
<link href="#rfc.section.2" rel="Chapter" title="2 Hjson Grammar"/>
<link href="#rfc.section.3" rel="Chapter" title="3 Values"/>
<link href="#rfc.section.4" rel="Chapter" title="4 Value Separators"/>
<link href="#rfc.section.5" rel="Chapter" title="5 Objects"/>
<link href="#rfc.section.6" rel="Chapter" title="6 Arrays"/>
<link href="#rfc.section.7" rel="Chapter" title="7 Numbers"/>
<link href="#rfc.section.8" rel="Chapter" title="8 Strings"/>
<link href="#rfc.section.8.1" rel="Chapter" title="8.1 JSON Strings"/>
<link href="#rfc.section.8.2" rel="Chapter" title="8.2 Quoteless Strings"/>
<link href="#rfc.section.8.3" rel="Chapter" title="8.3 Multiline Strings"/>
<link href="#rfc.section.9" rel="Chapter" title="9 String and Character Issues"/>
<link href="#rfc.section.9.1" rel="Chapter" title="9.1 Character Encoding"/>
<link href="#rfc.section.9.2" rel="Chapter" title="9.2 Unicode Characters"/>
<link href="#rfc.section.9.3" rel="Chapter" title="9.3 String Comparison"/>
<link href="#rfc.section.10" rel="Chapter" title="10 Parsers"/>
<link href="#rfc.section.11" rel="Chapter" title="11 Generators"/>
<link href="#rfc.section.12" rel="Chapter" title="12 IANA Considerations"/>
<link href="#rfc.section.13" rel="Chapter" title="13 Security Considerations"/>
<link href="#rfc.section.14" rel="Chapter" title="14 Examples"/>
<link href="#rfc.section.14.1" rel="Chapter" title="14.1 JSON vs Hjson"/>
<link href="#rfc.section.15" rel="Chapter" title="15 Contributors"/>
<link href="#rfc.references" rel="Chapter" title="16 Normative References"/>
<link href="#rfc.authors" rel="Chapter"/>
<meta name="generator" content="xml2rfc version 2.5.1 - http://tools.ietf.org/tools/xml2rfc" />
<link rel="schema.dct" href="http://purl.org/dc/terms/" />
<meta name="dct.creator" content="Zangl, C." />
<meta name="dct.identifier" content="urn:ietf:id:hjson-draft" />
<meta name="dct.issued" scheme="ISO8601" content="2016-5-23" />
<meta name="dct.abstract" content="Human JSON (Hjson) is a configuration file format based on the JavaScript Object Notation " />
<meta name="description" content="Human JSON (Hjson) is a configuration file format based on the JavaScript Object Notation " />
</head>
<body>
<table class="header">
<tbody>
<tr>
<td class="left">none</td>
<td class="right">C. Zangl</td>
</tr>
<tr>
<td class="left">Internet-Draft</td>
<td class="right">May 23, 2016</td>
</tr>
<tr>
<td class="left">Intended status: Standards Track</td>
<td class="right"></td>
</tr>
<tr>
<td class="left">Expires: November 24, 2016</td>
<td class="right"></td>
</tr>
</tbody>
</table>
<p class="title">The Human JSON (Hjson) Configuration Format<br />
<span class="filename">hjson-draft</span></p>
<h1 id="rfc.abstract">
<a href="#rfc.abstract">Abstract</a>
</h1>
<p>Human JSON (Hjson) is a configuration file format based on the JavaScript Object Notation <a href="#RFC7159">[RFC7159]</a>. Its focus is to provide a reasonable alternative to plain JSON configs that are hard to edit and do not allow comments.</p>
<h1 id="rfc.status">
<a href="#rfc.status">Status of This Memo</a>
</h1>
<p>This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.</p>
<p>Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.</p>
<p>Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."</p>
<p>This Internet-Draft will expire on November 24, 2016.</p>
<h1 id="rfc.copyrightnotice">
<a href="#rfc.copyrightnotice">Copyright Notice</a>
</h1>
<p>Copyright (c) 2016 IETF Trust and the persons identified as the document authors. All rights reserved.</p>
<p>This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.</p>
<p>This document may contain material from IETF Documents or IETF Contributions published or made publicly available before November 10, 2008. The person(s) controlling the copyright in some of this material may not have granted the IETF Trust the right to allow modifications of such material outside the IETF Standards Process. Without obtaining an adequate license from the person(s) controlling the copyright in such materials, this document may not be modified outside the IETF Standards Process, and derivative works of it may not be created outside the IETF Standards Process, except to format it for publication as an RFC or to translate it into languages other than English.</p>
<hr class="noprint" />
<h1 class="np" id="rfc.toc"><a href="#rfc.toc">Table of Contents</a></h1>
<ul class="toc">
<li>1. <a href="#rfc.section.1">Introduction</a></li>
<ul><li>1.1. <a href="#rfc.section.1.1">Syntax compared to JSON</a></li>
<li>1.2. <a href="#rfc.section.1.2">Conventions Used in This Document</a></li>
<li>1.3. <a href="#rfc.section.1.3">Specifications of Hjson</a></li>
</ul><li>2. <a href="#rfc.section.2">Hjson Grammar</a></li>
<li>3. <a href="#rfc.section.3">Values</a></li>
<li>4. <a href="#rfc.section.4">Value Separators</a></li>
<li>5. <a href="#rfc.section.5">Objects</a></li>
<li>6. <a href="#rfc.section.6">Arrays</a></li>
<li>7. <a href="#rfc.section.7">Numbers</a></li>
<li>8. <a href="#rfc.section.8">Strings</a></li>
<ul><li>8.1. <a href="#rfc.section.8.1">JSON Strings</a></li>
<li>8.2. <a href="#rfc.section.8.2">Quoteless Strings</a></li>
<li>8.3. <a href="#rfc.section.8.3">Multiline Strings</a></li>
</ul><li>9. <a href="#rfc.section.9">String and Character Issues</a></li>
<ul><li>9.1. <a href="#rfc.section.9.1">Character Encoding</a></li>
<li>9.2. <a href="#rfc.section.9.2">Unicode Characters</a></li>
<li>9.3. <a href="#rfc.section.9.3">String Comparison</a></li>
</ul><li>10. <a href="#rfc.section.10">Parsers</a></li>
<li>11. <a href="#rfc.section.11">Generators</a></li>
<li>12. <a href="#rfc.section.12">IANA Considerations</a></li>
<li>13. <a href="#rfc.section.13">Security Considerations</a></li>
<li>14. <a href="#rfc.section.14">Examples</a></li>
<ul><li>14.1. <a href="#rfc.section.14.1">JSON vs Hjson</a></li>
</ul><li>15. <a href="#rfc.section.15">Contributors</a></li>
<li>16. <a href="#rfc.references">Normative References</a></li>
<li><a href="#rfc.authors">Author's Address</a></li>
</ul>
<h1 id="rfc.section.1"><a href="#rfc.section.1">1.</a> <a href="#intro" id="intro">Introduction</a></h1>
<p id="rfc.section.1.p.1">Human JSON (Hjson) is a configuration file format. It is a superset of the JavaScript Object Notation <a href="#RFC7159">[RFC7159]</a>.</p>
<p id="rfc.section.1.p.2">Hjson uses the same four primitive types (strings, numbers, booleans, and null) and two structured types (objects and arrays) as JSON.</p>
<p id="rfc.section.1.p.3">A string is a sequence of zero or more Unicode characters <a href="#UNICODE">[UNICODE]</a>. Note that this citation references the latest version of Unicode rather than a specific release. It is not expected that future changes in the UNICODE specification will impact the syntax of Hjson.</p>
<p id="rfc.section.1.p.4">An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.</p>
<p id="rfc.section.1.p.5">An array is an ordered sequence of zero or more values.</p>
<p id="rfc.section.1.p.6">The terms “object” and “array” come from the conventions of JavaScript.</p>
<p id="rfc.section.1.p.7">Hjson’s design goals were</p>
<p/>
<ul>
<li>to improve readability and editability over JSON while keeping the familiar syntax intact</li>
<li>to maintain backward compatibility, so that any valid JSON is valid Hjson</li>
<li>to provide a reasonable alternative to plain JSON configs</li>
</ul>
<p id="rfc.section.1.p.9">Hjson SHOULD be used for data whose primary purpose is to be viewed or edited by a human. For example configuration, resource files or debug data dumps.</p>
<p id="rfc.section.1.p.10">Hjson SHOULD NOT be used in other cases, like transfer protocols.</p>
<h1 id="rfc.section.1.1"><a href="#rfc.section.1.1">1.1.</a> <a href="#syntax-compared-to-json" id="syntax-compared-to-json">Syntax compared to JSON</a></h1>
<p id="rfc.section.1.1.p.1">Hjson is a superset of JSON. Its syntax allows you to</p>
<p/>
<ul>
<li>add #, // or /**/ comments,</li>
<li>omit quotes for keys,</li>
<li>omit quotes for strings (terminated by LF, no escapes),</li>
<li>omit braces for the root object,</li>
<li>omit the comma at the end of a line</li>
<li>add trailing commas and</li>
<li>use multiline strings with proper whitespace handling.</li>
</ul>
<p id="rfc.section.1.1.p.3">Because the punctuator characters <samp>{}[],:</samp> are used to define the structure of the Hjson text, you need to use quotes</p>
<p/>
<ul>
<li>if your key includes a punctuator or space</li>
<li>if your string starts with a punctuator</li>
</ul>
<p id="rfc.section.1.1.p.5">For examples see <a href="#json-vs-hjson">Section 14.1</a>.</p>
<h1 id="rfc.section.1.2"><a href="#rfc.section.1.2">1.2.</a> <a href="#conventions-used-in-this-document" id="conventions-used-in-this-document">Conventions Used in This Document</a></h1>
<p id="rfc.section.1.2.p.1">The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in <a href="#RFC2119">[RFC2119]</a>.</p>
<p id="rfc.section.1.2.p.2">The grammatical rules in this document are to be interpreted as described in <a href="#RFC5234">[RFC5234]</a> except where they are specifically marked as <a href="#SABNF">[SABNF]</a>.</p>
<p id="rfc.section.1.2.p.3">SABNF is used to express grammars that are not possible in ABNF, like the block-comment, and to define terminators, like ql-end, that allow us to exclude certain sequences. These constructs allow us to generate parsers and to verify the grammar against test cases. For the general understanding of the language they can be ignored.</p>
<h1 id="rfc.section.1.3"><a href="#rfc.section.1.3">1.3.</a> <a href="#specifications-of-hjson" id="specifications-of-hjson">Specifications of Hjson</a></h1>
<p id="rfc.section.1.3.p.1">This document describes Hjson and registers the media type “application/hjson”.</p>
<h1 id="rfc.section.2"><a href="#rfc.section.2">2.</a> <a href="#hjson-grammar" id="hjson-grammar">Hjson Grammar</a></h1>
<p id="rfc.section.2.p.1">A Hjson text is a sequence of tokens. The set of tokens includes seven structural characters, comments, strings, numbers, and three literal names.</p>
<p id="rfc.section.2.p.2">A Hjson text is either a serialized value or a root object.</p>
<pre>
Hjson-text = ws-c ( root-object / value ) ws-c
</pre>
<p id="rfc.section.2.p.3">These are the seven structural characters:</p>
<pre>
begin-array = %x5B ; [ left square bracket
begin-object = %x7B ; { left curly bracket
end-array = %x5D ; ] right square bracket
end-object = %x7D ; } right curly bracket
name-separator = %x3A ; : colon
comma-separator = %x2C ; , comma
lf-separator = lf ; Line feed or New line
</pre>
<p id="rfc.section.2.p.4">Insignificant whitespace and comments are allowed before or after any of the first six structural characters.</p>
<pre>
ws-c = *( comment / ws )
ws = *( space / tab / lf / cr )
space = %x20 ; Space
tab = %x09 ; Horizontal tab
lf = %x0A ; Line feed or New line
cr = %x0D ; Carriage return
</pre>
<p id="rfc.section.2.p.5">Comments can be specified as line or block comments.</p>
<pre>
comment = line-comment / block-comment
line-comment = ( %x23 / ; # hash
%x2F.2F ) ; // slash + slash
*( tab / cr / %x20-10FFFF ) ; until lf
block-comment = start-block-comment
*( !end-block-comment anychar )
end-block-comment
start-block-comment = %x2F.2A ; /* slash + star
end-block-comment = %x2A.2F ; */ star + slash
anychar = tab / cr / lf / %x20-10FFFF
; SABNF: block-comment requies the use of the
; ! operator to allow * and / in the text
; while stopping at */
</pre>
<h1 id="rfc.section.3"><a href="#rfc.section.3">3.</a> <a href="#values" id="values">Values</a></h1>
<p id="rfc.section.3.p.1">A Hjson value MUST be an object, array, number, or string, or one of the following three literal names:</p>
<pre>
false = %x66.61.6C.73.65 ; false
null = %x6E.75.6C.6C ; null
true = %x74.72.75.65 ; true
</pre>
<p id="rfc.section.3.p.2">The literal names MUST be lowercase. No other literal names are allowed.</p>
<pre>
value = literal / object / array / number / string
literal = ( false / null / true ) !literal-end
literal-end =
*( space / tab )
( %x21-22 / %x24-2B / %x2D-2E / %x30-5A /
%x5C / %x5E-7A / %x7C / %x7E-10FFFF )
; exclude #/,[]{}
; SABNF: define literal-end to prevent matches
; that are actually a ql-string
; (like "true blue")
</pre>
<h1 id="rfc.section.4"><a href="#rfc.section.4">4.</a> <a href="#value-separators" id="value-separators">Value Separators</a></h1>
<p id="rfc.section.4.p.1">Values can be separated directly by a comma or indirectly by one or more linefeeds.</p>
<pre>
value-separator = ( ws-c comma-separator ws-c ) /
( *( comment /
*(space / tab / cr) )
lf-separator ws-c )
</pre>
<p id="rfc.section.4.p.2">Note that while Hjson allows the use of lf as a separator, the cr character is generally ignored. This should not be an issue as all modern operating systems use either lf or cr+lf as their line terminator.</p>
<h1 id="rfc.section.5"><a href="#rfc.section.5">5.</a> <a href="#objects" id="objects">Objects</a></h1>
<p id="rfc.section.5.p.1">An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members). A single colon comes after each name, separating the name from the value. A comma separates a value from the next name unless the value is followed by a linefeed, in which case the comma is optional. Trailing separators are allowed. The names within an object SHOULD be unique.</p>
<pre>
object = begin-object
ws-c
[ member *( value-separator member ) [value-separator] ]
ws-c
end-object
member = name ws-c name-separator ws-c value
</pre>
<p id="rfc.section.5.p.2">If the Hjson text defines an object it does not have to include the braces at the root level:</p>
<pre>
root-object =
member
*( value-separator member ) [value-separator]
</pre>
<p id="rfc.section.5.p.3">A name can be specified as a JSON string (with quotes) or as a name without quotes.</p>
<pre>
name = json-string / keyname
keyname = 1*non-punctuator-char
non-punctuator-char = %x21-2B / %x2D-39 / %x3B-5A /
%x5C / %x5E-7A / %x7C / %x7E-10FFFF
; any non-punctuator character (excludes ,:[]{} and ws)
</pre>
<p id="rfc.section.5.p.4">For interoperability issues regarding the uniquness of names and object member ordering, see <a href="#RFC7159">[RFC7159]</a> Section 4.</p>
<h1 id="rfc.section.6"><a href="#rfc.section.6">6.</a> <a href="#arrays" id="arrays">Arrays</a></h1>
<p id="rfc.section.6.p.1">An array structure is represented as square brackets surrounding zero or more values (or elements). Elements are separated by commas or linefeeds. Trailing commas are allowed.</p>
<pre>
array = begin-array
ws-c
[ value *( value-separator value ) [value-separator ] ]
ws-c
end-array
</pre>
<p id="rfc.section.6.p.2">There is no requirement that the values in an array be of the same type.</p>
<h1 id="rfc.section.7"><a href="#rfc.section.7">7.</a> <a href="#numbers" id="numbers">Numbers</a></h1>
<p id="rfc.section.7.p.1">The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed.</p>
<p id="rfc.section.7.p.2">A fraction part is a decimal point followed by one or more digits.</p>
<p id="rfc.section.7.p.3">An exponent part begins with the letter E in upper or lower case, which may be followed by a plus or minus sign. The E and optional sign are followed by one or more digits.</p>
<p id="rfc.section.7.p.4">Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.</p>
<pre>
number = [ minus ] int [ frac ] [ exp ] !num-end
decimal-point = %x2E ; .
digit = %x30-39 ; 0-9
digit1-9 = %x31-39 ; 1-9
e = %x65 / %x45 ; e E
exp = e [ minus / plus ] 1*digit
frac = decimal-point 1*digit
int = zero / ( digit1-9 *digit )
minus = %x2D ; -
plus = %x2B ; +
zero = %x30 ; 0
num-end = *( space / tab )
( %x21-22 / %x24-2B / %x2D-2E / %x30-5A /
%x5C / %x5E-7A / %x7C / %x7E-10FFFF )
; exclude #/,[]{}
; SABNF: define num-end to prevent matches
; that are actually a ql-string
; (like "1 minute")
</pre>
<p id="rfc.section.7.p.5">For limits on the range and precision of numbers see <a href="#RFC7159">[RFC7159]</a> Section 6.</p>
<h1 id="rfc.section.8"><a href="#rfc.section.8">8.</a> <a href="#strings" id="strings">Strings</a></h1>
<p id="rfc.section.8.p.1">Hjson allows strings to be represented in three different formats.</p>
<pre>
string = json-string / ml-string / ql-string
</pre>
<h1 id="rfc.section.8.1"><a href="#rfc.section.8.1">8.1.</a> <a href="#json-strings" id="json-strings">JSON Strings</a></h1>
<p id="rfc.section.8.1.p.1">The representation of JSON strings is similar to conventions used in the C family of programming languages. A string begins and ends with quotation marks. All Unicode characters may be placed within the quotation marks, except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).</p>
<p id="rfc.section.8.1.p.2">Any character may be escaped. If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF), then it may be represented as a six-character sequence: a reverse solidus, followed by the lowercase letter u, followed by four hexadecimal digits that encode the character’s code point. The hexadecimal letters A though F can be upper or lower case. So, for example, a string containing only a single reverse solidus character may be represented as “\u005C”.</p>
<p id="rfc.section.8.1.p.3">Alternatively, there are two-character sequence escape representations of some popular characters. So, for example, a string containing only a single reverse solidus character may be represented more compactly as “\”.</p>
<p id="rfc.section.8.1.p.4">To escape an extended character that is not in the Basic Multilingual Plane, the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair. So, for example, a string containing only the G clef character (U+1D11E) may be represented as “\uD834\uDD1E”.</p>
<pre>
json-string = quotation-mark *char quotation-mark
char = unescaped /
escape (
%x22 / ; " quotation mark U+0022
%x5C / ; \ reverse solidus U+005C
%x2F / ; / solidus U+002F
%x62 / ; b backspace U+0008
%x66 / ; f form feed U+000C
%x6E / ; n line feed U+000A
%x72 / ; r carriage return U+000D
%x74 / ; t tab U+0009
%x75 4hexdig ) ; uXXXX U+XXXX
hexdig = %x30-39 / "A" / "B" / "C" / "D" / "E" / "F"
escape = %x5C ; \
quotation-mark = %x22 ; "
unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
</pre>
<h1 id="rfc.section.8.2"><a href="#rfc.section.8.2">8.2.</a> <a href="#quoteless-strings" id="quoteless-strings">Quoteless Strings</a></h1>
<p id="rfc.section.8.2.p.1">Hjson allows strings to be represented only by their content without quotes. A quoteless string may contain any character except the control characters (U+0000 through U+001F), excluding trailing whitespace. It cannot start with a punctuator character (,:[]{}). It ends at the first linefeed. Strings are taken as is without escapes.</p>
<pre>
ql-string = non-punctuator-char
*( !ql-end ql-char )
ql-end = *( space / tab / cr ) lf
ql-char = space / tab / %x21-10FFFF
; SABNF: define ql-end to exclude trailing
; whitespace from the ql-string
</pre>
<p id="rfc.section.8.2.p.2">A Hjson parser must still detect values (<em>number</em>, <samp>true</samp>, <samp>false</samp> or <samp>null</samp>) and parse them correctly. For example</p>
<p/>
<ul>
<li>‘3’ is the number 3</li>
<li>‘5 times’ is the string “5 times”</li>
<li>‘true’ is the boolean true</li>
<li>‘7 # minutes’ is the number 7 followed by a comment</li>
<li>’\s#([0-9a-fA-F]{3})’ is the string “\\s#([0-9a-fA-F]{3})”</li>
</ul>
<p id="rfc.section.8.2.p.4">Not allowing escapes inside the quoteless string allows you to specify HTML fragments, regular expressions or Windows style paths as-is, keeping them readable.</p>
<h1 id="rfc.section.8.3"><a href="#rfc.section.8.3">8.3.</a> <a href="#multiline-strings" id="multiline-strings">Multiline Strings</a></h1>
<p id="rfc.section.8.3.p.1">A multiline string begins and ends with three single quotes.</p>
<pre>
ml-string =
ml-seq
*( !ml-seq ( ml-char / ml-ignore ) )
ml-seq
ml-seq = "'''"
ml-char = space / tab / lf / %x21-10FFFF
ml-ignore = cr
; SABNF: ml-string requies the use of the
; ! operator to allow ' in the text
; while stopping at '''
</pre>
<p id="rfc.section.8.3.p.2">The carrige return character is generally ignored to make the parser platform independent.</p>
<p id="rfc.section.8.3.p.3">Whitespace handling cannot be expressed in the ABNF grammar and is thus defined as:</p>
<p/>
<ul>
<li>Whitespace on the first line is ignored.</li>
<li>The first three single quotes define the head. On the following lines all whitespace up to the column of the first single quote is ignored.</li>
<li>All other whitespace is assumed to be part of the string.</li>
<li>The last newline is ignored to allow for better formatting.</li>
</ul>
<h1 id="rfc.section.9"><a href="#rfc.section.9">9.</a> <a href="#string-and-character-issues" id="string-and-character-issues">String and Character Issues</a></h1>
<h1 id="rfc.section.9.1"><a href="#rfc.section.9.1">9.1.</a> <a href="#character-encoding" id="character-encoding">Character Encoding</a></h1>
<p id="rfc.section.9.1.p.1">Hjson text SHALL be encoded in UTF-8. Since Hjson parsers can read JSON they may be able to read texts in other encodings (such as UTF-16 and UTF-32). Hjson texts that are encoded in UTF-8 are interoperable in the sense that they will be read successfully by the maximum number of implementations.</p>
<p id="rfc.section.9.1.p.2">Implementations MUST NOT add a byte order mark to the beginning of a Hjson text. In the interests of interoperability, implementations that parse Hjson texts MAY ignore the presence of a byte order mark rather than treating it as an error.</p>
<h1 id="rfc.section.9.2"><a href="#rfc.section.9.2">9.2.</a> <a href="#unicode-characters" id="unicode-characters">Unicode Characters</a></h1>
<p id="rfc.section.9.2.p.1">See <a href="#RFC7159">[RFC7159]</a> Section 8.2.</p>
<h1 id="rfc.section.9.3"><a href="#rfc.section.9.3">9.3.</a> <a href="#string-comparison" id="string-comparison">String Comparison</a></h1>
<p id="rfc.section.9.3.p.1">See <a href="#RFC7159">[RFC7159]</a> Section 8.3.</p>
<h1 id="rfc.section.10"><a href="#rfc.section.10">10.</a> <a href="#parsers" id="parsers">Parsers</a></h1>
<p id="rfc.section.10.p.1">A Hjson parser transforms a Hjson text into another representation. A Hjson parser MUST accept all texts that conform to the Hjson grammar. A Hjson parser MAY accept non-Hjson forms or extensions.</p>
<p id="rfc.section.10.p.2">An implementation may set limits on the size of texts that it accepts. An implementation may set limits on the maximum depth of nesting. An implementation may set limits on the range and precision of numbers. An implementation may set limits on the length and character contents of strings.</p>
<h1 id="rfc.section.11"><a href="#rfc.section.11">11.</a> <a href="#generators" id="generators">Generators</a></h1>
<p id="rfc.section.11.p.1">A Hjson generator produces Hjson text. The resulting text MUST strictly conform to the Hjson grammar.</p>
<h1 id="rfc.section.12"><a href="#rfc.section.12">12.</a> <a href="#iana-considerations" id="iana-considerations">IANA Considerations</a></h1>
<p id="rfc.section.12.p.1">The MIME media type for Hjson text is application/hjson.</p>
<p id="rfc.section.12.p.2">Type name: application</p>
<p id="rfc.section.12.p.3">Subtype name: hjson</p>
<p id="rfc.section.12.p.4">Required parameters: n/a</p>
<p id="rfc.section.12.p.5">Optional parameters: n/a</p>
<p id="rfc.section.12.p.6">Encoding considerations: binary</p>
<p id="rfc.section.12.p.7">Security considerations: See XXXX, <a href="#sec">Section 13</a>.</p>
<p id="rfc.section.12.p.8">Interoperability considerations: Described in XXXX</p>
<p id="rfc.section.12.p.9">Published specification: XXXX</p>
<p id="rfc.section.12.p.10">Applications that use this media type: Hjson has been used to provide configuration data for applications written in all of these programming languages: C#, Go, Java, JavaScript, PHP and Python</p>
<p id="rfc.section.12.p.11">Additional information: Magic number(s): n/a File extension(s): .hjson Macintosh file type code(s): TEXT</p>
<p id="rfc.section.12.p.12">Person & email address to contact for further information: IESG <a href="mailto:[email protected]">[email protected]</a></p>
<p id="rfc.section.12.p.13">Intended usage: COMMON</p>
<p id="rfc.section.12.p.14">Restrictions on usage: none</p>
<p id="rfc.section.12.p.15">Author: Christian Zangl <a href="mailto:[email protected]">[email protected]</a></p>
<p id="rfc.section.12.p.16">Change controller: IESG <a href="mailto:[email protected]">[email protected]</a></p>
<p id="rfc.section.12.p.17">Note: No “charset” parameter is defined for this registration. Adding one really has no effect on compliant recipients.</p>
<h1 id="rfc.section.13"><a href="#rfc.section.13">13.</a> <a href="#sec" id="sec">Security Considerations</a></h1>
<p id="rfc.section.13.p.1">Unlike JSON, Hjson is not a subset of Javascript and cannot be parsed using “eval()”.</p>
<h1 id="rfc.section.14"><a href="#rfc.section.14">14.</a> <a href="#examples" id="examples">Examples</a></h1>
<p id="rfc.section.14.p.1">This is a Hjson object:</p>
<pre>
# comments are useful
# specify rate in requests/second
rate: 1000
# you may also use
// c style
/* or block
comments */
# key names do not need to be placed in
# quotes unless they contain a punctuator
# character {}[],:
key: 1
# strings may also omit quotes if they do
# not start with a punctuator
text: look ma, no quotes!
# quoteless strings do not use escapes
# and end at the LF/newline
# commas are optional
commas:
{
one: 1
two: 2
}
# trailing commas are allowed
trailing:
{
one: 1,
two: 2,
}
# multiline string
haiku:
'''
JSON I love you.
But you strangle my expression.
This is so much better.
'''
# Hjson is a superset of JSON so you
# may use any valid JSON syntax:
favNumbers: [ 1, 2, 3, 6, 42 ]
</pre>
<h1 id="rfc.section.14.1"><a href="#rfc.section.14.1">14.1.</a> <a href="#json-vs-hjson" id="json-vs-hjson">JSON vs Hjson</a></h1>
<p id="rfc.section.14.1.p.1">Example of a document processor configuration, first in JSON:</p>
<pre>
{
"header": "The Foo Manual\nCopyright Bar Inc.",
"source": {
"include": [
"./src"
],
"includePattern": ".+\\.foo(doc)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"templates": {
"cleverLinks": false,
"monospaceLinks": false
}
}
</pre>
<p id="rfc.section.14.1.p.2">and in Hjson:</p>
<pre>
# define the header using a multiline string
header:
'''
The Foo Manual
Copyright Bar Inc.
'''
source:
{
# generate documentation for these paths
include:
[
./src
]
# include/exclude files
# notice that no escapes are required
includePattern: .+\.foo(doc)?$
excludePattern: (^|\/|\\)_
}
templates: {
# trailing commas are allowed
cleverLinks: false,
monospaceLinks: false,
}
</pre>
<p id="rfc.section.14.1.p.3">Example of a npm dependency configuration in JSON:</p>
<pre>
{
"dependencies": {
"foo": "2.0.1",
"bar": "*",
"til": "~1.2.1",
"elf": "^1.2.3"
}
}
</pre>
<p id="rfc.section.14.1.p.4">and in Hjson:</p>
<pre>
{
dependencies:
{
// match version exactly
foo: 2.0.1
// * matches any version
bar: *
// approximately, allows patch-level changes
til: ~1.2.1
// compatible with major version
elf: ^1.2.3
}
}
</pre>
<h1 id="rfc.section.15"><a href="#rfc.section.15">15.</a> <a href="#contributors" id="contributors">Contributors</a></h1>
<p id="rfc.section.15.p.1">This document is based on <a href="#RFC4627">[RFC4627]</a> and <a href="#RFC7159">[RFC7159]</a> which were written by Douglas Crockford and Tim Bray. This document was constructed by extending it with the elements of the Hjson syntax.</p>
<h1 id="rfc.references"><a href="#rfc.references">16.</a> Normative References</h1>
<table>
<tbody>
<tr>
<td class="reference">
<b id="RFC2119">[RFC2119]</b>
</td>
<td class="top"><a>Bradner, S.</a>, "<a href="http://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997.</td>
</tr>
<tr>
<td class="reference">
<b id="RFC4627">[RFC4627]</b>
</td>
<td class="top"><a>Crockford, D.</a>, "<a href="http://tools.ietf.org/html/rfc4627">The application/json Media Type for JavaScript Object Notation (JSON)</a>", RFC 4627, DOI 10.17487/RFC4627, July 2006.</td>
</tr>
<tr>
<td class="reference">
<b id="RFC5234">[RFC5234]</b>
</td>
<td class="top"><a>Crocker, D.</a> and <a>P. Overell</a>, "<a href="http://tools.ietf.org/html/rfc5234">Augmented BNF for Syntax Specifications: ABNF</a>", STD 68, RFC 5234, DOI 10.17487/RFC5234, January 2008.</td>
</tr>
<tr>
<td class="reference">
<b id="RFC7159">[RFC7159]</b>
</td>
<td class="top"><a>Bray, T.</a>, "<a href="http://tools.ietf.org/html/rfc7159">The JavaScript Object Notation (JSON) Data Interchange Format</a>", RFC 7159, DOI 10.17487/RFC7159, March 2014.</td>
</tr>
<tr>
<td class="reference">
<b id="SABNF">[SABNF]</b>
</td>
<td class="top"><a>Thomas, L.</a>, "<a href="https://github.com/ldthomas/apg-js2/blob/2fa136e00e5932d70ed1bd4786101c87afa8ca2e/SABNF.md">Superset Augmented Backus-Naur Form</a>", version 2.2.1, n.d..</td>
</tr>
<tr>
<td class="reference">
<b id="UNICODE">[UNICODE]</b>
</td>
<td class="top"><a>The Unicode Consortium</a>, "<a href="http://www.unicode.org/versions/latest/">The Unicode Standard</a>", n.d..</td>
</tr>
</tbody>
</table>
<h1 id="rfc.authors">
<a href="#rfc.authors">Author's Address</a>
</h1>
<div class="avoidbreak">
<address class="vcard">
<span class="vcardline">
<span class="fn">Christian Zangl</span>
<span class="n hidden">
<span class="family-name">Zangl</span>