Context
explode can represent both objects and arrays as arrays of { key, value } entries. implode currently infers the source shape from the key types:
- numeric keys produce an array
- string keys produce an object
This inference cannot distinguish an empty object from an empty array because both explode to []. Consequently, an empty-array round trip currently behaves like this:
explode([]) // []
implode([]) // {}
Suggestion
Allow the transformer definition to specify the intended shape explicitly, for example:
{ $transform: "explode", type: "array" }
{ $transform: "explode", type: "object" }
The exact property name is open for discussion. When provided, it could:
- resolve the empty-input ambiguity in the inverse direction
- optionally validate that entry keys are compatible with the declared shape
- make the transformation contract clearer for integrations with a known schema
Without an explicit shape, the current key-based inference could remain the default for compatibility.
Acceptance considerations
- Add forward and reverse tests for empty objects and empty arrays.
- Document behavior when the declared shape conflicts with entry key types.
- Decide whether the option belongs to both
explode and implode, or whether direction handling makes one shared option sufficient.
Context
explodecan represent both objects and arrays as arrays of{ key, value }entries.implodecurrently infers the source shape from the key types:This inference cannot distinguish an empty object from an empty array because both explode to
[]. Consequently, an empty-array round trip currently behaves like this:Suggestion
Allow the transformer definition to specify the intended shape explicitly, for example:
The exact property name is open for discussion. When provided, it could:
Without an explicit shape, the current key-based inference could remain the default for compatibility.
Acceptance considerations
explodeandimplode, or whether direction handling makes one shared option sufficient.