-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathjson-js.javascript.txt
49 lines (43 loc) · 3.51 KB
/
json-js.javascript.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
┏━━━━━━━━━━━━━┓
┃ JSON-JS ┃
┗━━━━━━━━━━━━━┛
VERSION ==> #Native implementation in JavaScript
JSON.parse #From 'JSON' to JavaScript.
('JSON'[, FUNC(KEY, VAL)[->VAL]][, OPTS]) #FUNC():
# - transform VAL after parsing (but does not parse it)
# - from children to parent
# - ends with root object: key '', this {'': OBJ}
# - `this` is current [sub-]object
# - returning undefined omits property
#Can throw SyntaxError.
*-|~#OPTS:
*-|~# - source STR: using same serialization as JSON.rawJSON()
JSON.stringify(VAL[, VAL2[, STR|NUM]]) #From JavaScript to 'JSON'
#Transformation:
# - NaN|[-]Infinity -> null.
# - Non-plain OBJ -> plain OBJ
# - undefined|FUNC|SYM:
# - top-level -> undefined
# - OBJ property -> omitted
# - ARR item -> null
# - key that is SYM|non-enumerable -> omitted
# - ARR property -> omitted
# - OBJ.toJSON()->VAL -> VAL
#Can throw TypeError on:
# - infinite recursion
# - BIGINT
-#Invalid UTF-8 sequences (e.g. JSON.stringify('\udead')) are escaped (e.g. '\\udead')
#VAL2 can be:
# - FUNC(KEY, VAL)[->VAL]: like JSON.parse() but:
# - transform VAL before serialization (but does not serialize it)
# - from parent to children
# - KEY_ARR:
# - same as FUNC(KEY, VAL) { if (KEY_ARR.includes(KEY)) { return VAL; }}
# - is independant of property depth
#STR|NUM adds newlines and indents with STR or NUM spaces.
JSON.rawJSON(VAL)->STR *-|~#Serialize BOOL|STR|NUM|BIGINT|null as it is written in JavaScript
*-|~# - STR keeps quotes
*-|~# - NUM keeps specific number notation
*-|~#Other types throw
*-|~#Meant to be used in JSON.stringify() FUNC, as a conterpart to JSON.parse() OPTS.source
JSON.isRawJSON(VAL)->BOOL *-|~#