json: add serializer for hashtables

chris.double 2006-08-07 11:41:40 +00:00
parent e9b351119b
commit bd4f48f9c2
1 changed files with 10 additions and 1 deletions

View File

@ -72,3 +72,12 @@ M: sequence json-print ( array -- string )
M: object json-print ( object -- string )
CHAR: { write1 slots slots>fields "," join write CHAR: } write1 ;
: hash-map ( hashtable quot -- array )
>r hash>alist r> [ dup first swap second ] swap append map ;
M: hashtable json-print ( hashtable -- string )
CHAR: { write1
[ [ swap jsvar-encode >json % CHAR: : , >json % ] "" make ] hash-map "," join write
CHAR: } write1 ;