Skip to content

parseObject

Parses a value into a non-null, non-array object. This parser uses the validateObject structural validator to ensure that the input is an object whose typeof is "object", excluding null and arrays.

The parser never throws and never mutates input. It returns a structured ParseResult<object> describing success or failure.

Signature

function parseObject(
    value: unknown,
    field?: string
): ParseResult<object>

Behavior

  • Accepts:
  • Plain objects.
  • Objects with a null prototype.
  • Class instances.
  • Objects with the any prototype.
  • Rejects:
  • Arrays.
  • Functions.
  • Primitives.
  • null and undefined.
  • Never mutates input.
  • Never throws.

Returns

  • ok: true: And the original object when parsing succeeds.
  • ok: false, value: null: And a list of issues when parsing fails.

Examples

parseObject({ a: 1 })
// { ok: true, value: { a: 1 }, issues: [] }

parseObject(null)
// { ok: false, value: null, issues: ["Value must be an object"] }

Notes