{ $values { "string" "a string in JSON format" } { "object" "a deserialized object" } }
{ $description "Deserializes the JSON formatted string into a Factor object. JSON objects are converted to Factor hashtables. All other JSON objects convert to their obvious Factor equivalents." } ;
-HELP: read-json-objects
-{ $values { "objects" "a vector of deserialized objects" } }
+HELP: read-json
+{ $values { "objects" { $sequence "deserialized objects" } } }
{ $description "Reads JSON formatted strings into a vector of Factor object until the end of the stream is reached. JSON objects are converted to Factor hashtables. All other JSON objects convert to their obvious Factor equivalents." } ;
ARTICLE: "json.reader" "JSON reader"
"The " { $vocab-link "json.reader" } " vocabulary defines a word for parsing strings in JSON format."
-{ $subsections json> read-json-objects } ;
+{ $subsections json> read-json } ;
ABOUT: "json.reader"
! A properly formed JSON input should contain exactly one object with balanced brackets.
-: get-json-object ( objects -- obj )
+: get-json ( objects -- obj )
dup length 1 = counter get 0 = and [ first ] [ json-error ] if ;
PRIVATE>
-: read-json-objects ( -- objects )
+: read-json ( -- objects )
input-stream get json-read-input ;
GENERIC: json> ( string -- object )
M: string json>
- [ 0 counter [ read-json-objects get-json-object ] with-variable ] with-string-reader ;
+ [ 0 counter [ read-json get-json ] with-variable ] with-string-reader ;
: path>json ( path -- json )
- utf8 [ 0 counter [ read-json-objects get-json-object ] with-variable ] with-file-reader ;
+ utf8 [ 0 counter [ read-json get-json ] with-variable ] with-file-reader ;