Skip to content

Decode

[<Class>]
type Decode =
    helpers: IDecoderHelpers<JsonElement>
    static member fromString<'T> (codec: Codec<'T>) : string -> Result<'T,string>
    static member fromString<'T> (decoder: Decoder<'T>) : string -> Result<'T,string>
    static member fromStringWithOptions<'T> (options: JsonDocumentOptions, codec: Codec<'T>) : string -> Result<'T,string>
    static member fromStringWithOptions<'T> (options: JsonDocumentOptions, decoder: Decoder<'T>) : string -> Result<'T,string>
    static member fromValue<'T> (codec: Codec<'T>) : JsonElement -> Result<'T,string>
    static member fromValue<'T> (decoder: Decoder<'T>) : JsonElement -> Result<'T,string>
    static member unsafeFromString<'T> (codec: Codec<'T>) : string -> 'T
    static member unsafeFromString<'T> (decoder: Decoder<'T>) : string -> 'T
AssemblyRanvier.Wire

Runs a decoder against System.Text.Json.

Functions and values

helpers: IDecoderHelpers<JsonElement>

Reads a JsonElement, so a decoder written against Thoth.Json.Core runs on System.Text.Json.

Methods

static member fromString<'T> (codec: Codec<'T>) : string -> Result<'T,string>

Parse a JSON string and run the decoder half of a codec against it.

static member fromString<'T> (decoder: Decoder<'T>) : string -> Result<'T,string>

Parse a JSON string and run the decoder against it.

Returns. Ok with the decoded value, or Error with the formatted message.

static member fromStringWithOptions<'T> (options: JsonDocumentOptions, codec: Codec<'T>) : string -> Result<'T,string>

Parse a JSON string with caller-supplied JsonDocumentOptions and run the decoder half of a codec against it.

let options = JsonDocumentOptions(MaxDepth = 256)

json |> Decode.fromStringWithOptions(options, codec)
static member fromStringWithOptions<'T> (options: JsonDocumentOptions, decoder: Decoder<'T>) : string -> Result<'T,string>

Parse a JSON string with caller-supplied JsonDocumentOptions and run the decoder against it.

Use it to raise MaxDepth beyond its default of 64, to allow trailing commas, or to skip comments.

let options = JsonDocumentOptions(MaxDepth = 256)

json |> Decode.fromStringWithOptions(options, decoder)
static member fromValue<'T> (codec: Codec<'T>) : JsonElement -> Result<'T,string>

Run the decoder half of a codec against a JsonElement which is already parsed.

static member fromValue<'T> (decoder: Decoder<'T>) : JsonElement -> Result<'T,string>

Run a decoder against a JsonElement which is already parsed.

static member unsafeFromString<'T> (codec: Codec<'T>) : string -> 'T

Parse a JSON string and run the decoder half of a codec, raising an exception carrying the message on failure.

static member unsafeFromString<'T> (decoder: Decoder<'T>) : string -> 'T

Parse a JSON string and run the decoder, raising an exception carrying the message on failure.