Skip to content

No empty object values

noEmptyObjectValues validates that a plain object does not contain any empty plain objects in its own enumerable properties.

It performs a strict structural check ensuring the value is a plain object, then inspects each property value for empty plain objects. If the value is not a plain object or contains any empty objects, the rule emits a single validation event. Otherwise, it produces no validation output.

Signature

Through the API:

.noEmptyObjectValues()

And internally:

export const noEmptyObjectValues: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>

Events

Event code Description
object.not.plain-object Value is not a JSON-compatible plain object
object.has.empty-object Object contains at least one empty plain object

Design rationale

  • Provides a strict, predictable empty object prohibition.
  • First ensures the value is a plain object, then checks all property values.
  • Rejects any property that has a plain object with zero keys.
  • Useful for enforcing data quality where empty nested objects should be avoided.
  • Never coerces or normalizes — validation is explicit and opt-in.
  • Emits exactly one event per failure for clarity and composability.
  • Async-compatible and returns a readonly array of JaneEvent objects.

Invoke

noEmptyObjectValues runs only when explicitly included in a boundary or pipeline. It does not run automatically.

The rule activates when:

  • The value is any JavaScript value.
  • If the value is not a plain object, emits object.not.plain-object.
  • If the value is a plain object but contains any empty objects, emits object.has.empty-object.
  • If the value is a plain object with no empty nested objects → returns an empty result set.

Examples

Valid object with no empty nested objects

await noEmptyObjectValues({ name: "John", address: { city: "NYC" } }, "$");
// → []

Object with empty nested object

await noEmptyObjectValues({ name: "John", address: {} }, "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "object.has.empty-object",
//       path: "$",
//       ...
//     }
//   ]

Array (invalid)

await noEmptyObjectValues([1, 2, 3], "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "object.not.plain-object",
//       path: "$",
//       ...
//     }
//   ]