mini-effect
    Preparing search index...

    Function json

    • Reads the response body as parsed JSON.

      Parameters

      • response: Response

        The Response whose body to read as JSON

      Returns Effect<unknown, Failure<"FailedToRead">, never, never>

      An Effect that resolves with unknown or fails with a FailedToRead tagged error

      Wraps Response.json() in an Effect. The result type is unknown since JSON parsing does not guarantee a specific shape — use mini-effect/schema with validate for runtime validation. If reading fails, the error is wrapped in a FailedToRead tagged error that can be caught with catchTags.

      import { pipe, run } from "mini-effect";
      import { request, json } from "mini-effect/fetch";

      const data = await run(
      pipe(request("https://api.example.com/data"), (res) => json(res)),
      );