The JSONParser
structure implements a parser for the
JSON.value
type.
Synopsis
structure JSONParser
Interface
type source
val openStream : TextIO.instream -> source
val openFile : string -> source
val openString : string -> source
val close : source -> unit
val parse : source -> JSON.value
val parseFile : string -> JSON.value
Description
type source
-
The abstract type of JSON input sources. Note that this type is the same as
JSONStreamParser.source
.
val openStream : TextIO.instream → source
-
openStream inS
returns a input source for the given input stream.
val openFile : string → source
-
openStream file
returns a input source for the given file. This function opens an input stream for reading from the file, so one should make sure to callclose
on the source once all of the JSON values have been read from the file. val openString : string → source
-
openStream s
returns a input source for the given string.
val close : source → unit
-
close src
closes the input source, which has the effect of marking the source as closed. Furthermore, ifsrc
was created by a call toopenFile
, then the underlying input stream that was created for the file is closed. This function does not close the input stream for sources created byopenStream
val parse : source -> JSON.value
-
parse src
parses a JSON value from the input sourcesrc
. Ifsrc
is closed or if there is a syntax error, then theFail
exception is raised. val parseFile : string -> JSON.value
-
parse f
parses a JSON value from the text filef
. If there is a syntax error, then theFail
exception is raised. This function can also raise theIo
exception if there is an error openingf
. Note that this function will only parse a single JSON value from the file; to parse multiple values, one should used theparse
function with a source created byopenFile
.