Remove empty array keys¶
removeEmptyArrayKeys is a built‑in normalization rule that removes object keys whose values are empty arrays.
This eliminates structurally empty list fields while preserving all non‑empty array data. If the value is not a plain object, or no keys contain empty arrays, no normalization step is emitted.
Signature¶
export const removeEmptyArrayKeys: NormalizationRule<unknown>
(value: unknown, mode: NormalizationMode, path: FieldPath) => NormalizationStep[]
Events¶
| Event code | Description |
|---|---|
object.without.empty-arrays |
Keys with empty array values were removed. |
Design rationale¶
- Removes only keys whose values are empty arrays (
[]). - Preserves all non‑empty arrays and all non‑array values.
- Eliminates structural noise originating from UI frameworks, partial form submissions, or API responses that include empty list placeholders.
- Emits a normalization step only when at least one empty array key is removed.
- Classified as
lossynormalization — the original empty array values are discarded. - Produces cleaner object shapes for downstream validators, scanners, and policy layers.
Invoke¶
removeEmptyArrayKeys 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 array keys removed¶
const value = {
items: [],
tags: ["a", "b"],
meta: []
};
const result = removeEmptyArrayKeys(value, "lax", "$");
// → [
// {
// path: "$",
// nextValue: { tags: ["a", "b"] },
// lossy: "lossy",
// events: [
// JaneEvent{ kind: "info", code: "object.without.empty-arrays", ... }
// ]
// }
// ]
No empty arrays — no normalization¶
const result = removeEmptyArrayKeys({ a: [1], b: [] }, "strict", "$");
// → []
Non‑object value¶
const result = removeEmptyArrayKeys("not an object", "lax", "$");
// → []