forked from ehmicky/Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.format.txt
More file actions
92 lines (74 loc) · 6.07 KB
/
json.format.txt
File metadata and controls
92 lines (74 loc) · 6.07 KB
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
┏━━━━━━━━━━┓
┃ JSON ┃
┗━━━━━━━━━━┛
ALTERNATIVES ==> #See serialization formats summary
STANDARDS ==> #ECMA-404
#RFC 8259: more detailed
I-JSON ==> #RFC 7493
#I-JSON ("Internet JSON"), restrictive version of JSON for maximum
#interoperability between parsers.
NOTATION ==> !#Means recommended but implementation-specific
!!#Means recommended but implementation-specific, and required by I-JSON
GOAL ==> #Serialization format based on JavaScript
#Extension: .json
#MIME type: application/json
┌────────────┐
│ SYNTAX │
└────────────┘
CASE ==> #Case-sensitive
WHITESPACES|NEWLINES ==> #Is space, tab, CR or LF
#Whitespaces|newlines are ignored:
# - at start|end
# - between tokens
ENCODING ==> #UTF-8
#No byte-order mark
LIMITS ==> !#Implementation-specific
!#On depth level, input size, STR sixe, ARR|OBJ length, key length
{"VAR": VAL} #OBJ
#Must double-quote "VAR"
#No trailing commas
#VAR: same restrictions as STR
!!#No duplicate keys
!!#Is unordered
[VAL,...] #ARR
#No trailing commas
"..." #STR.
#No single quotes
#Any Unicode supported unescaped except " \ and U+0000-U+001F (\-escaped)
# - i.e. significant newline must be escaped
# - U+2028|2029 (line separators) allowed unescaped in JSON and ES2018 (Node >=10),
# but not in ES2017 or before
!!# - when used as OBJ key "VAR", must be normalized for duplication check
#Can use backslash sequences (fewer than JavaScript):
# \" \\ \b \f \n \r \t \/
# \uXXXX
# - U+010000-U+10FFFF can only be used unescaped
!!# - must be valid codepoint
[-]NUM[.NUM][e|E[+|-]NUM] #FLOAT.
#No leading comma (e.g. ".7")
#No +NUM
#No Infinity|NaN
#No leading zero (e.g. "07")
#Only base 10
#Not specified:
# - max size
!!# - double floats
# - overflow, underflow, rounding
# - whether can normalize NUM <-> NUM.0 (INT vs FLOAT)
# - whether can normalize 0 <-> -0
true|false #BOOL
null #
TOP-LEVEL ==> !!#OBJ|ARR
RECURSION ==> #Not possible.
COMPARISON WITH JAVASCRIPT ==> #No undefined, FUNC or native objects (besides OBJ|ARR)
#Can however support others:
# - if toJSON() defined:
# - DATE.toJSON()->DATE.toISOString()
!!# DATE must follow ISO8601/RFC3339, which DATE.toISOString() does
!!# - binary should be base64 STR (base64url variant)
# - by calling toString() prior
# - via JSON.stringify|parse FUNC
#Does not handle any ES6-specific syntax, like { [STR]: VAL }, { VAR }, SYM, etc.
#Unescaped U+2028|2029 in "..." allowed only starting from ES2018