46 lines
957 B
Text
46 lines
957 B
Text
|
|
construct json namespace {
|
|
_StringyJSON
|
|
;
|
|
props-to-sjson { s | with spaces props this ;
|
|
def value, comma
|
|
"," spaces if { " " concat } =comma
|
|
|
|
props:last:get<1> =value
|
|
value null eq not if {
|
|
value gettype "array" eq if {
|
|
"[" value
|
|
:iter
|
|
:map<| 0 swap properties this:props-to-sjson>
|
|
:join<comma> concat
|
|
"]" concat
|
|
3 stop
|
|
}
|
|
"\""
|
|
value _str :replace<"\\" "\\\\">:replace<"\"" "\\\""> concat
|
|
"\"" concat
|
|
2 stop
|
|
}
|
|
|
|
"{"
|
|
props
|
|
:iter
|
|
:filter<{ b | :to-stack pop with key ; key ":" eq not key ";" eq not and }>
|
|
:map<{ s |
|
|
:to-stack with key value ;
|
|
"\""
|
|
key :replace<"\\" "\\\\">:replace<"\"" "\\\""> concat
|
|
"\":" concat spaces if { " " concat }
|
|
spaces value properties this:props-to-sjson concat
|
|
}>
|
|
:join<comma> concat
|
|
"}" concat
|
|
}
|
|
}
|
|
|
|
construct json:_StringyJSON {
|
|
;
|
|
sjson { s | with spaces this ;
|
|
spaces this properties json:props-to-sjson
|
|
}
|
|
}
|