Skip to content

Function: parseRecord()

parseRecord(text): Record<string, unknown> | undefined

Parse JSON text that is expected to be an object, returning undefined when it is absent, malformed, or parses to a non-record (an array, a bare string, null, …).

This is the common case for manifests, env-var config blobs, and untyped API payloads: parse followed by isRecord, so the result can be indexed without an as Record<string, unknown> cast.

unknown

Record<string, unknown> | undefined

const manifest = json.parseRecord(await readFile("package.json", "utf8")) ?? {};
const name = manifest.name;