function parseJsonBody
Since 0.5.0
parseJsonBody(text: string): unknown

Parses one request-body text as JSON, the ONE parse all three IRequest json() implementations share (X37-1, M90f).

The served HTTP path (@setu-ts/runtime), the kernel's inject(), and @setu-ts/testing's MockRequest each used to run their own JSON.parse, so fixing the malformed-body status at one of them left the other two answering a different status for the same request — and fixing only the kernel's would have made every served request answer 500 while the in-process test path answered 400. One shared parse keeps the @throws contract on IRequest.json true at every producer.

Parameters

text: string

The body text to parse

Return Type

unknown

The parsed JSON value

Throws

MalformedRequestBodyError

When text is not valid JSON; the platform SyntaxError is carried as cause

Usage

import { parseJsonBody } from "common/src/index.ts";