import { decoder } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { json } = decoder;
A Decoder combinator that will check that a value is a string and then attempt to parse it as JSON.
Examples
Example 1
Example 1
import * as D from "./decoder.ts";
import { pipe } from "./fn.ts";
const person = D.struct({
name: D.string,
age: D.number,
});
const json = D.json(person);
const result1 = json(null); // Left(DecodeError)
const result2 = json(""); // Left(DecodeError)
const result3 = json('{"name":"Brandon","age":37}');
// Right({ name: "Brandon", age: 37 })