-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.io
47 lines (38 loc) · 982 Bytes
/
json.io
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
OperatorTable addAssignOperator(":", "assign")
JSON := Map clone do(
curlyBrackets := method(
_m := JSON clone
call message arguments foreach(arg,
_m doMessage(arg)
)
)
squareBrackets := method(
call message arguments map(x, doMessage(x))
)
assign := method(key, value,
atPut(
// Because the first argument is treated as a name in Io,
// we need to remove the quotation mark
key asMutable removePrefix("\"") removeSuffix("\""),
value
)
)
readFromString := method(str,
doString(str)
)
readFromFile := method(filename,
readFromString(File with(filename) openForReading contents)
)
stringfy := method(
"{ " .. self map(key, value, key .. ": " .. (value stringfy)) join(", ") asString .. " }"
)
)
List stringfy := method(
"[" .. map(x, x stringfy) join(", ") .. "]"
)
Sequence stringfy := method(
"\"" .. self asString .. "\""
)
Object stringfy := method(
call target asString
)