The SML of NJ Library
The `JSONParser` structure

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 call `close` 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, if `src` was created by a call to `openFile`, then the underlying input stream that was created for the file is closed. This function does not close the input stream for sources created by `openStream`

`val parse : source -> JSON.value`

  `parse src` parses a JSON value from the input source `src`. If `src` is closed or if there is a syntax error, then the `Fail` exception is raised.

`val parseFile : string -> JSON.value`

  `parse f` parses a JSON value from the text file `f`. If there is a syntax error, then the `Fail` exception is raised. This function can also raise the `Io` exception if there is an error opening `f`. Note that this function will only parse a single JSON value from the file; to parse multiple values, one should used the `parse` function with a source created by `openFile`.

## See Also

`JSON`, `JSONStreamParser`, `JSONUtil`, The JSON Library

SML/NJ Version 110.99.3 (August 1, 2023)
Last updated 2023-07-31 17:59:01 UTC