JSON
Decoders for validating JSON-compatible values.
json
json: Decoder<JSONValue> (source)
Accepts any value that's a valid JSON value.
In other words: any value returned by JSON.parse() should decode without failure.
type JSONValue = null | string | number | boolean | { [string]: JSONValue } | JSONValue[];Try it
| Input | Result |
|---|---|
| { "name": "Amir", "age": 27, "admin": true, "image": null, "tags": [ "vip" ] } | |
| "hello" | |
| 42 | |
| null | |
| true | |
| [1, 2, 3] |
jsonObject
jsonObject: Decoder<{ [string]: JSONValue }> (source)
Accepts objects that contain only valid JSON values.
Try it
| Input | Result |
|---|---|
| {} | |
| { "name": "Amir" } | |
| [] ^^ Must be an object | |
| [ { "name": "Alice", }, ] ^ Must be an object | |
| "hello" ^^^^^^^ Must be an object | |
| null ^^^^ Must be an object |
jsonArray
jsonArray: Decoder<JSONValue[]> (source)
Accepts arrays that contain only valid JSON values.
Try it
| Input | Result |
|---|---|
| [] | |
| [{ "name": "Amir" }] | |
| {} ^^ Must be an array | |
| { "name": "Alice", } ^ Must be an array | |
| "hello" ^^^^^^^ Must be an array | |
| null ^^^^ Must be an array |