Decode
bool
RESCRIPT
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
RESCRIPTJSON.parseExn(`true`)->JSON.Decode.bool
// Some(true)
JSON.parseExn(`"hello world"`)->JSON.Decode.bool
// None
null
RESCRIPT
let null: t => option<Core__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
RESCRIPTJSON.parseExn(`null`)->JSON.Decode.null
// Some(null)
JSON.parseExn(`"hello world"`)->JSON.Decode.null
// None
string
RESCRIPT
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
RESCRIPTJSON.parseExn(`"hello world"`)->JSON.Decode.string
// Some("hello world")
JSON.parseExn(`42`)->JSON.Decode.string
// None
float
RESCRIPT
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
RESCRIPTJSON.parseExn(`42.0`)->JSON.Decode.float
// Some(42.0)
JSON.parseExn(`"hello world"`)->JSON.Decode.float
// None
object
RESCRIPT
let object: t => option<Core__Dict.t<t>>
Decodes a single JSON value. If the value is an object, it will return Some(Dict.t)
- otherwise it will return None
.
Examples
RESCRIPTJSON.parseExn(`{"foo":"bar"}`)->JSON.Decode.object
// Some({ foo: 'bar' })
JSON.parseExn(`"hello world"`)->JSON.Decode.object
// None
array
RESCRIPT
let array: t => option<array<t>>