Skip to content

Decode

module Decode
AssemblyRanvier.Wire
Attributes[<RequireQualifiedAccess>]

Declared inside

Advanced
Enum
Getters
Helpers
IGetters
IOptionalGetter
IRequiredGetter

Functions and values

all<'a> (decoders: Decoder<'a> list) : Decoder<'a list>

Run every decoder against the same value, and collect their results.

andMap<'a, 'b>: Decoder<'a> -> Decoder<('a -> 'b)> -> Decoder<'b>

Apply one decoded value to a decoded function, for building a value field by field.

type Point =
{
X : float
Y : float
}

module Point =
let create x y = { X = x; Y = y }

let decode =
Decode.succeed create
|> Decode.andMap (Decode.field "x" Decode.float)
|> Decode.andMap (Decode.field "y" Decode.float)
andThen<'a, 'b> (cb: 'a -> Decoder<'b>) (decoder: Decoder<'a>) : Decoder<'b>

Use the result of a decoder to choose the next one.

array<'value> (decoder: Decoder<'value>) : Decoder<'value array>

Decode a JSON array into an array.

at<'value> (fieldNames: string list) (decoder: Decoder<'value>) : Decoder<'value>

Decode the value at a path of property names.

bigint: Decoder<bigint>

Decode a JSON string or number into a bigint.

bool: Decoder<bool>

Decode a JSON boolean.

byte: Decoder<byte>

Alias to Decode.uint8

char: Decoder<char>

Decode a JSON string into an F# char.

Decode.fromString Decode.char "a" == Ok 'a'
Decode.fromString Decode.char "ab" == Error ...
Decode.fromString Decode.char "true" == Error ...
Decode.fromString Decode.char "42" == Error ...
codec<'t> (c: Codec<'t>) : Decoder<'t>

The decoder half of a codec.

datetimeLocal: Decoder<DateTime>

Decode a System.DateTime with DateTime.TryParse; uses default System.DateTimeStyles.

datetimeOffset: Decoder<DateTimeOffset>

Decode a JSON string into a DateTimeOffset.

datetimeUtc: Decoder<DateTime>

Decode a System.DateTime value using Sytem.DateTime.TryParse, then convert it to UTC.

decimal: Decoder<decimal>

Decode a JSON string or number into a decimal.

dict<'value> (decoder: Decoder<'value>) : Decoder<Map<string,'value>>

Decode an object into a map keyed by the property names.

errorToString<'JsonValue> (helpers: IDecoderHelpers<'JsonValue>) (path: string, error: ErrorReason<'JsonValue>) : string

Format a decoding failure as the message the entry points return.

fail<'a> (msg: string) : Decoder<'a>

Always fail with the given message.

field<'value> (fieldName: string) (decoder: Decoder<'value>) : Decoder<'value>

Decode the value under a property.

fix<'a> (make: Decoder<'a> -> Decoder<'a>) : Decoder<'a>

Allow to build a decoder that can call itself

type Tree =
| Empty
| Branch of Tree * int * Tree

module Tree =

let decode =
Decode.fix
(fun self ->
Decode.oneOf
[
Decode.unit
|> Decode.map (fun () -> Tree.Empty)

Decode.tuple3 self Decode.int self
|> Decode.map Tree.Branch
])
float: Decoder<float>

Decode a JSON number into a float.

float32: Decoder<float32>

Decode a JSON number into a float32.

guid: Decoder<Guid>

Decode a JSON string into an F# Guid.

Decode.fromString Decode.guid "58bd4436-7583-40e2-bd3c-aa3c5d0b4286" == Ok (System.Guid "58bd4436-7583-40e2-bd3c-aa3c5d0b4286")
Decode.fromString Decode.guid "58bd4436-aa3c5d0b4286" == Error ...
index<'value> (requestedIndex: int) (decoder: Decoder<'value>) : Decoder<'value>

Decode the element of an array at the given position.

int: Decoder<int>

Decode a JSON number or string into an int.

int16: Decoder<int16>

Decode a JSON number or string into an int16.

int64: Decoder<int64>

Decode a JSON string or number into an int64.

keyValuePairs<'value> (decoder: Decoder<'value>) : Decoder<(string * 'value) list>

Decode every property of an object, giving its name paired with its decoded value.

keys: Decoder<string list>

The property names of an object.

lazily<'t> (x: Lazy<Decoder<'t>>) : Decoder<'t>

Defer the construction of a decoder until it is first used, for mutually recursive types.

list<'value> (decoder: Decoder<'value>) : Decoder<'value list>

Decode a JSON array into a list.

losslessOption<'value> (decoder: Decoder<'value>) : Decoder<'value option>

Decode the object written by losslessOption into an option.

Round-trips at any nesting depth, at the cost of a heavier representation.

lossyOption<'value> (decoder: Decoder<'value>) : Decoder<'value option>

Decode null into None, and anything else with the given decoder.

Lossy: a nested option does not round-trip. Use losslessOption when you need the distinction.

map<'a, 'Output> (ctor: 'a -> 'Output) (d1: Decoder<'a>) : Decoder<'Output>

Transform the result of a decoder.

map'<'key, 'value when 'key: comparison> (keyDecoder: Decoder<'key>) (valueDecoder: Decoder<'value>) : Decoder<Map<'key,'value>>

Decode an array of [ key, value ] pairs into a map. Use it when the key is not a string.

map2<'a, 'b, 'Output> (ctor: 'a -> 'b -> 'Output) (d1: Decoder<'a>) (d2: Decoder<'b>) : Decoder<'Output>

Decode with two decoders and combine their results.

map3<'a, 'b, 'c, 'Output> (ctor: 'a -> 'b -> 'c -> 'Output) (d1: Decoder<'a>) (d2: Decoder<'b>) (d3: Decoder<'c>) : Decoder<'Output>

Decode with three decoders and combine their results.

map4<'a, 'b, 'c, 'd, 'Output> (ctor: 'a -> 'b -> 'c -> 'd -> 'Output) (d1: Decoder<'a>) (d2: Decoder<'b>) (d3: Decoder<'c>) (d4: Decoder<'d>) : Decoder<'Output>

Decode with four decoders and combine their results.

map5<'a, 'b, 'c, 'd, 'e, 'Output> (ctor: 'a -> 'b -> 'c -> 'd -> 'e -> 'Output) (d1: Decoder<'a>) (d2: Decoder<'b>) (d3: Decoder<'c>) (d4: Decoder<'d>) (d5: Decoder<'e>) : Decoder<'Output>

Decode with five decoders and combine their results.

map6<'a, 'b, 'c, 'd, 'e, 'f, 'Output> (ctor: 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'Output) (d1: Decoder<'a>) (d2: Decoder<'b>) (d3: Decoder<'c>) (d4: Decoder<'d>) (d5: Decoder<'e>) (d6: Decoder<'f>) : Decoder<'Output>

Decode with six decoders and combine their results.

map7<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'Output> (ctor: 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'Output) (d1: Decoder<'a>) (d2: Decoder<'b>) (d3: Decoder<'c>) (d4: Decoder<'d>) (d5: Decoder<'e>) (d6: Decoder<'f>) (d7: Decoder<'g>) : Decoder<'Output>

Decode with seven decoders and combine their results.

map8<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'Output> (ctor: 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'Output) (d1: Decoder<'a>) (d2: Decoder<'b>) (d3: Decoder<'c>) (d4: Decoder<'d>) (d5: Decoder<'e>) (d6: Decoder<'f>) (d7: Decoder<'g>) (d8: Decoder<'h>) : Decoder<'Output>

Decode with eight decoders and combine their results.

nil<'a> (output: 'a) : Decoder<'a>

Decode null into the given value, and fail on anything else.

notNone<'a> (decoder: Decoder<'a option>) : Decoder<'a>

Turn a decoder of an option into one which fails on None.

object<'value> (builder: IGetters -> 'value) : Decoder<'value>

Decode an object, reading each property through get.Required or get.Optional.

let pointDecoder =
Decode.object (fun get ->
{
X = get.Required.Field "x" Decode.int
Y = get.Required.Field "y" Decode.int
}
)
oneOf<'value> (decoders: Decoder<'value> list) : Decoder<'value>

Decode with the first decoder of the list that succeeds.

The decoders are tried in order. If all of them fail, the failure reports every one.

optional<'value> (fieldName: string) (decoder: Decoder<'value>) : Decoder<'value option>

Decode the value under a property, giving None when the property is missing or null.

Fails when the property is there but the decoder rejects its value.

optionalAt<'value> (fieldNames: string list) (decoder: Decoder<'value>) : Decoder<'value option>

Decode the value at a path of property names, giving None when the path is missing or holds null.

requireSome<'a> (errorMessage: string) (decoder: Decoder<'a option>) : Decoder<'a>

Turn None into a failure carrying the given message.

resizeArray<'value> (decoder: Decoder<'value>) : Decoder<ResizeArray<'value>>

Decode a JSON array into a ResizeArray.

sbyte: Decoder<sbyte>

Decode a JSON number or string into an sbyte.

seq<'value> (decoder: Decoder<'value>) : Decoder<'value seq>

Decode a JSON array into a sequence.

string: Decoder<string>

Decode a JSON string into an F# string.

Decode.fromString Decode.string "Hello" == Ok "Hello"
Decode.fromString Decode.string "42" == Error ...
Decode.fromString Decode.string "true" == Error ...
Decode.fromString Decode.string "{ \"foo\": 42 }" == Error ...
succeed<'a> (output: 'a) : Decoder<'a>

Always succeed with the given value, whatever the JSON.

timespan: Decoder<TimeSpan>

Decode a JSON string into a TimeSpan.

tuple2<'T1, 'T2> (decoder1: Decoder<'T1>) (decoder2: Decoder<'T2>) : Decoder<'T1 * 'T2>

Decode a JSON array of 2 elements into a tuple.

tuple3<'T1, 'T2, 'T3> (decoder1: Decoder<'T1>) (decoder2: Decoder<'T2>) (decoder3: Decoder<'T3>) : Decoder<'T1 * 'T2 * 'T3>

Decode a JSON array of 3 elements into a tuple.

tuple4<'T1, 'T2, 'T3, 'T4> (decoder1: Decoder<'T1>) (decoder2: Decoder<'T2>) (decoder3: Decoder<'T3>) (decoder4: Decoder<'T4>) : Decoder<'T1 * 'T2 * 'T3 * 'T4>

Decode a JSON array of 4 elements into a tuple.

tuple5<'T1, 'T2, 'T3, 'T4, 'T5> (decoder1: Decoder<'T1>) (decoder2: Decoder<'T2>) (decoder3: Decoder<'T3>) (decoder4: Decoder<'T4>) (decoder5: Decoder<'T5>) : Decoder<'T1 * 'T2 * 'T3 * 'T4 * 'T5>

Decode a JSON array of 5 elements into a tuple.

tuple6<'T1, 'T2, 'T3, 'T4, 'T5, 'T6> (decoder1: Decoder<'T1>) (decoder2: Decoder<'T2>) (decoder3: Decoder<'T3>) (decoder4: Decoder<'T4>) (decoder5: Decoder<'T5>) (decoder6: Decoder<'T6>) : Decoder<'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6>

Decode a JSON array of 6 elements into a tuple.

tuple7<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7> (decoder1: Decoder<'T1>) (decoder2: Decoder<'T2>) (decoder3: Decoder<'T3>) (decoder4: Decoder<'T4>) (decoder5: Decoder<'T5>) (decoder6: Decoder<'T6>) (decoder7: Decoder<'T7>) : Decoder<'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7>

Decode a JSON array of 7 elements into a tuple.

tuple8<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'T8> (decoder1: Decoder<'T1>) (decoder2: Decoder<'T2>) (decoder3: Decoder<'T3>) (decoder4: Decoder<'T4>) (decoder5: Decoder<'T5>) (decoder6: Decoder<'T6>) (decoder7: Decoder<'T7>) (decoder8: Decoder<'T8>) : Decoder<'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8>

Decode a JSON array of 8 elements into a tuple.

uint16: Decoder<uint16>

Decode a JSON number or string into a uint16.

uint32: Decoder<uint32>

Decode a JSON number or string into a uint32.

uint64: Decoder<uint64>

Decode a JSON string or number into a uint64.

unit: Decoder<unit>

Decode a JSON null value into an F# unit.

Decode.fromString Decode.unit "null" == Ok ()
Decode.fromString Decode.unit "42" == Error ...
uri: Decoder<Uri>

Decode a JSON string into a System.Uri.

The string is parsed with UriKind.RelativeOrAbsolute, so both absolute (e.g. https://example.com) and relative (e.g. /path?query=1) URIs are accepted.

Decode.fromString Decode.uri "\"https://example.com\"" == Ok (System.Uri "https://example.com")
value: Decoder<Json>

Decode any JSON into a Json tree.