diff --git a/basis/json/reader/reader-tests.factor b/basis/json/reader/reader-tests.factor index fa6c8d7d3a..14a54b89c0 100644 --- a/basis/json/reader/reader-tests.factor +++ b/basis/json/reader/reader-tests.factor @@ -33,6 +33,7 @@ IN: json.reader.tests { 8 9 10 12 13 34 47 92 } >string 1array [ <" "\b\t\n\f\r\"\/\\" "> json> ] unit-test { HEX: abcd } >string 1array [ <" "\uaBCd" "> json> ] unit-test +{ H{ { "a" { } } { "b" 123 } } } [ "{\"a\":[],\"b\":123}" json> ] unit-test { { } } [ "[]" json> ] unit-test { { 1 "two" 3.0 } } [ <" [1, "two", 3.0] "> json> ] unit-test { H{ } } [ "{}" json> ] unit-test diff --git a/basis/json/reader/reader.factor b/basis/json/reader/reader.factor index 1544af55cf..9886e316d7 100644 --- a/basis/json/reader/reader.factor +++ b/basis/json/reader/reader.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2008 Peter Burns, 2009 Philipp Winkler ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs combinators io io.streams.string json -kernel math math.parser math.parser.private sequences strings ; +kernel math math.parser math.parser.private prettyprint +sequences strings vectors ; IN: json.reader array over push ; + : (close-hash) ( accum -- accum' ) dup length 3 >= [ v-over-push ] when dup dup [ pop ] dip pop swap zip H{ } assoc-clone-like over push ; : scan ( accum char -- accum ) + ! 2dup . . ! Great for debug... [ { { CHAR: \" [ j-string over push ] } { CHAR: [ [ V{ } clone over push ] } { CHAR: , [ v-over-push ] } - { CHAR: ] [ v-over-push dup pop >array over push ] } + { CHAR: ] [ (close-array) ] } { CHAR: { [ 2 [ V{ } clone over push ] times ] } { CHAR: : [ v-pick-push ] } { CHAR: } [ (close-hash) ] }