-
Notifications
You must be signed in to change notification settings - Fork 5
/
spec.txt
98 lines (74 loc) · 1.77 KB
/
spec.txt
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
Canonical JSON
1. Introduction
Canonical JSON is a variant of JSON in which values each have a single,
unambiguous serialized form. This provides meaningful and repeatable hashes
of encoded data. Canonical JSON can be parsed by regular JSON parsers provided
that no control characters appear in strings.
2. Differences from JSON
- Whitespace between tokens is disallowed. Leading and trailing whitespace
is likewise disallowed.
- Floating point numbers, exponents and "minus zero" are all disallowed.
- Object keys must appear in lexiographical order and must not be repeated.
- Strings are uninterpreted bytes, with the only escaped byte values being
backslash and quote. Escaping is mandatory for those two characters.
- String contents are not guaranteed be parsable as UTF-8. Be aware that
encoded data may contain embedded control characters and nulls.
3. Example
JSON:
{
"foo": "bar",
"abc": 9e3,
"snowman": "\u2603",
"zoo":
[
"zorilla",
"anteater"
]
}
Canonical JSON:
{"abc":9000,"foo":"bar","snowman":"☃","zoo":["zorilla","anteater"]}
4. Grammar
value:
object
array
string
number
true
false
null
object:
{}
{ members }
members:
pair
pair , members
pair:
string : value
array:
[]
[ elements ]
elements:
value
value , elements
string:
""
" chars "
chars:
char
char chars
char:
any byte except hex 22 (") or hex 5C (\)
\\
\"
number:
int
int:
digit
digit1-9 digits
- digit1-9
- digit1-9 digits
digits:
digit
digit digits
5. References
Spec derived from: http://wiki.laptop.org/go/Canonical_JSON