#344·toon

`fillna` option without explicit replacer

Author: yilmazhasanCreated Sep 30, 2026Updated Sep 30, 2026
Labelsenhancement

Problem Statement

When any of the list object fields doesn't exists, simply list object fields don't match; the result differs.

The app considers all these list item objects/dictionaries as different types, but mostly they would be the same type.

Such as if it's a user list all objects in that list would be User type no matter if any user misses a field.

To make it more compact, a new option e.g. {fillna: null} as a default value would be nice to have.

Example:

javascript
const data = [
  { sku: 'A1', price: 9.99 },
  { sku: 'B2', qty: 2 }
]

toon.encode({ items2 }) would return:

items2[2]:
  - sku: A1
    price: 9.99
  - sku: B2
    qty: 2

Proposed Solution

However the more compact one could have been:

items2[2]{sku,price,qty}:
  A1,9.99,null
  B2,null,2

Even we could add default values for missing fields.

I propose a new option {fillna: null} or {fillna: {qty: 1, price: 0}}.

I could handle the task in case it's considered nice to have.

Alternatives Considered

Having a replacer could also work, but the replacer would be complex here.

Also this might be needed frequently so having a short-cut looks better.

SPEC Compliance

No response

Additional Context

No response