UseReadJsonFile
katanakit-js / useReadJsonFile
Function: useReadJsonFile()
Section titled “Function: useReadJsonFile()”function useReadJsonFile<T>(path, schema?): Promise<FilesystemResult<T>>;Defined in: infrastructure/filesystem/filesystem.service.ts:282
Reads and parses a JSON file, optionally validating it with a Zod schema.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type | Description |
|---|---|---|
T |
unknown |
Expected parsed (and validated) shape. |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
path |
string |
File path. |
schema? |
ZodType<T, unknown, $ZodTypeInternals<T, unknown>> |
Optional Zod schema; invalid shapes fail with ERR_VALIDATION. |
Returns
Section titled “Returns”Promise<FilesystemResult<T>>
Safe Result with the parsed data, or ERR_INVALID_JSON / ERR_VALIDATION.
Example
Section titled “Example”import { z } from "zod";
const BookSchema = z.object({ title: z.string() });const result = await useReadJsonFile("data/books.json", BookSchema);