Remove empty object keys¶
removeEmptyObjectKeys is a built‑in normalization rule that removes object keys whose values are empty plain objects.
This clears structural placeholders that carry no semantic content while preserving all non‑empty object values. If the value is not a plain object, or no keys contain empty objects, no normalization step is emitted.
Signature¶
export const removeEmptyObjectKeys: NormalizationRule<unknown>
(value: unknown, mode: NormalizationMode, path: FieldPath) => NormalizationStep[]
Events¶
| Event code | Description |
|---|---|
object.without.empty-objects |
Keys with empty object values were removed. |
Design rationale¶
- Removes only keys whose values are empty plain objects (
{}). - Preserves all non‑empty objects and all non‑object values.
- Eliminates structural noise from UI frameworks, form libraries, and API responses that include empty object placeholders.
- Emits a normalization step only when at least one empty object key is removed.
- Classified as
lossynormalization — the original empty object values are discarded. - Produces cleaner, more meaningful object shapes for downstream validators, scanners, and policy layers.
Invoke¶
removeEmptyObjectKeys runs automatically when:
- The value is structurally a plain object (not an array).
- The normalization stage is active.
- The current mode allows
lossynormalization.
Mode behavior:
strict: Rule does not run (lossy).moderate: Rule does not run (lossy).lax: Rule runs.
Normalization cannot be invoked manually. It is always applied automatically based on structural type and mode.
Examples¶
Empty object keys removed¶
const value = {
meta: {},
config: { enabled: true },
extra: {}
};
const result = removeEmptyObjectKeys(value, "lax", "$");
// → [
// {
// path: "$",
// nextValue: { config: { enabled: true } },
// lossy: "lossy",
// events: [
// JaneEvent{ kind: "info", code: "object.without.empty-objects", ... }
// ]
// }
// ]
No empty objects — no normalization¶
const result = removeEmptyObjectKeys({ a: { x: 1 }, b: {} }, "strict", "$");
// → []
Non‑object value¶
const result = removeEmptyObjectKeys("not an object", "lax", "$");
// → []