-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathjson-js-cycle.javascript.txt
25 lines (21 loc) · 1.71 KB
/
json-js-cycle.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
┏━━━━━━━━━━━━━━━━━━━┓
┃ JSON-JS-CYCLE ┃
┗━━━━━━━━━━━━━━━━━━━┛
ALTERNATIVES ==> #stringify-only(), replacing circular refs by placeholder:
# - isaacs json-stringify-safe: node.js only
# - debitoor safe-json-stringify: node.js only, handles toJSON(),
# replace ES5 getters that throw by placeholder
# - core module UTIL.inspect('%j') (preferred): node.js only, handles toJSON()
#stringify()+parse():
# - json-js-cycle (prefered):
# replaces circular refs by JSON paths
# - webreflection circular-json:
# replaces circular refs by JSON-pointers-like (using ~ as delimiter instead of /)
# - circular-json-es6: node.js only,
# denormalize OBJ into an OBJ_ARR to handle circular refs, need ES6 map support
VERSION ==> #2016-10-28
#Is cycle.js file from douglascrockford/JSON-js
JSON.decycle(OBJ[,FUNC(OBJ)->OBJ])#Replaces circular refs by { $ref STR } where STR is JSON path (bracket notation) from root
->OBJ ##FUNC is a map function called on each value
#Returns deep copy
JSON.retrocycle(OBJ)->OBJ #Restore references