> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# unchecked-json-cast

> Parsed JSON, a response body or a request body is cast to a type without a schema check or type guard.

## What it flags

A TypeScript cast of untyped outside data to a specific type: `JSON.parse(text) as T`, `(await response.json()) as T`, `response.json() as Promise<T>` and `req.body as T`. The cast tells the compiler the shape is right without checking it, so a missing or wrongly typed field passes type checking and fails later, far from the boundary.

The finding is at the default level when the data comes straight from a request: `req.body` or `ctx.request.body`, `await request.json()` on a handler's request parameter, or `JSON.parse(event.body)` in a Lambda handler. Parsed text, fetch responses and casts to a type parameter of the enclosing function are contextual.

It stays quiet when the same function validates something with a schema or guard: zod, valibot, yup, joi, superstruct or io-ts (`parse`, `safeParse`, `validate`, `decode`, `is`, `assert`), typia, ajv, TypeBox `Check`, class-validator and class-transformer (`validate`, `validateOrReject`, `plainToInstance`), or a named guard such as `isOrder(value)` or `parseOrder(value)`. Casts that claim nothing beyond the parser's own result (`unknown`, primitives, `object`, `Record<string, unknown>`, `unknown[]`, fields typed `unknown`, `Partial<T>`, optionally with `| null`) and `JSON.parse(JSON.stringify(value))` clones are also left alone. Test, generated and vendored files are skipped.

## How to review

Validate the value with a schema at the boundary, such as `OrderInput.parse(req.body)` with zod, or narrow it with a type guard. Answer a request with a 400 when validation fails. Mark a trusted source with `// loadwise-reviewed unchecked-json-cast -- <reason>` on the line above.

## Configuration

Set the rule to `"off"` in `loadwise.config.json` to drop its findings:

```json theme={null}
{
  "rules": { "unchecked-json-cast": "off" }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.