Decode

array

RES
let array: t => option<array<t>>

Decodes a single JSON value. If the value is an array, it will return Some(array) - otherwise it will return None.

Examples

RES
JSON.parseOrThrow(`["foo", "bar"]`)->JSON.Decode.array // Some([ 'foo', 'bar' ]) JSON.parseOrThrow(`"hello world"`)->JSON.Decode.array // None

bool

RES
let bool: t => option<bool>

Decodes a single JSON value. If the value is a bool, it will return Some(bool) - otherwise it will return None.

Examples

RES
JSON.parseOrThrow(`true`)->JSON.Decode.bool // Some(true) JSON.parseOrThrow(`"hello world"`)->JSON.Decode.bool // None

float

RES
let float: t => option<float>

Decodes a single JSON value. If the value is a float, it will return Some(float) - otherwise it will return None.

Examples

RES
JSON.parseOrThrow(`42.0`)->JSON.Decode.float // Some(42.0) JSON.parseOrThrow(`"hello world"`)->JSON.Decode.float // None

null

RES
let null: t => option<Null.t<'a>>

Decodes a single JSON value. If the value is null, it will return Some(Null.t) - otherwise it will return None.

Examples

RES
JSON.parseOrThrow(`null`)->JSON.Decode.null // Some(null) JSON.parseOrThrow(`"hello world"`)->JSON.Decode.null // None

object

RES
let object: t => option<dict<t>>

Decodes a single JSON value. If the value is an object, it will return Some(dict) - otherwise it will return None.

Examples

RES
JSON.parseOrThrow(`{"foo":"bar"}`)->JSON.Decode.object // Some({ foo: 'bar' }) JSON.parseOrThrow(`"hello world"`)->JSON.Decode.object // None

string

RES
let string: t => option<string>

Decodes a single JSON value. If the value is a string, it will return Some(string) - otherwise it will return None.

Examples

RES
JSON.parseOrThrow(`"hello world"`)->JSON.Decode.string // Some("hello world") JSON.parseOrThrow(`42`)->JSON.Decode.string // None