2006-08-07
JSON parser for Factor
I've implemented a simple JSON parser for Factor following RFC 4627. It will be available soon from the standard Factor repository and is also available from my darcs repository:
darcs get http://www.bluishcoder.co.nz/repos/factor
The three main words in the 'json' vocabulary are '>json', 'json-print' and 'json>'. An example of use is:
"json" require
USE: json
TUPLE: foo a b ;
"hi" "there" <foo> >json print
=> "{"a" : "hi", "b" : "there"}
"[ 10, 20, \"foo\", { \"value\" : 1e2 } ]" json> .
=> { 10 20 "foo" H{ { "value" 100 } } }
Factor tuples are converted to Javascript objects. Going the other way, Javascript objects are converted to Factor hashtables.