fix json arrays
This commit is contained in:
parent
c33b25f260
commit
fd0aed81fd
2 changed files with 28 additions and 5 deletions
26
spl/json.spl
26
spl/json.spl
|
@ -3,9 +3,25 @@ construct json namespace {
|
|||
_StringyJSON
|
||||
;
|
||||
props-to-sjson { s | with spaces props this ;
|
||||
props:last:get<1> dup null eq not if {
|
||||
"\"" swap _str :replace<"\\" "\\\\">:replace<"\"" "\\\""> concat "\"" concat 2 stop
|
||||
} pop
|
||||
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
|
||||
|
@ -15,9 +31,9 @@ construct json namespace {
|
|||
"\""
|
||||
key :replace<"\\" "\\\\">:replace<"\"" "\\\""> concat
|
||||
"\":" concat spaces if { " " concat }
|
||||
spaces value properties this:props-to-json concat
|
||||
spaces value properties this:props-to-sjson concat
|
||||
}>
|
||||
:join<", "> concat
|
||||
:join<comma> concat
|
||||
"}" concat
|
||||
}
|
||||
}
|
||||
|
|
7
test.spl
7
test.spl
|
@ -6,6 +6,7 @@
|
|||
"spl/time.spl" import
|
||||
"spl/httpserver/base.spl" import
|
||||
"spl/linkedlist.spl" import
|
||||
"spl/json.spl" import
|
||||
|
||||
|
||||
"SPL tester" =program-name
|
||||
|
@ -329,6 +330,12 @@ func main { int | with args ;
|
|||
|
||||
^ok =>? ^error not if { println }
|
||||
|
||||
"" println
|
||||
"json test" println
|
||||
|
||||
0 [ 0 1 2 "hi" ] properties json:props-to-sjson println
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue