Skip to content

Encoder emits an empty-object table cell as a valueless key: line, which decode then drops ([{"a":{}}] -> [{}]) #63

Description

@antrixy

Description

When toon-python encodes an array of objects (a "table") and a cell value is an empty
object {}, it emits the key as a bare "key:" line with no value. Decoding that back drops
the key, so the round-trip loses data. This is an encoder bug: it reproduces whenever
toon-python encodes (python->ts and python->python) but not on ts->python, so the
decoder is fine and the loss is in the representation toon-python emits. The reference
impl @toon-format/toon round-trips [{"a":{}}] correctly.

Reproduction Steps

  1. from toon_format import encode, decode
  2. toon = encode([{"a":{}}])
  3. decode(toon)

Expected Behavior

The round-trip preserves the value: decode(encode([{"a":{}}])) == [{"a":{}}].
(The reference impl @toon-format/toon does this correctly.)

Actual Behavior

encode([{"a":{}}]) produces:

[1]:
  -
    a:

The "a" key is emitted with no value. decode() of that returns:

[{}]

The "a" key has been dropped.

Environment

toon-python (toon_format): 0.9.0b1
reference impl @toon-format/toon: v2.3.0 (round-trips this input correctly)
Python: 3.14

Additional Context

The key name is irrelevant — [{"a":{}}] and [{"n":{}}] both reproduce it.

In a larger table, a {}-valued cell collapses the whole row:
input: [{"a":1,"b":2},{"a":{},"b":4}]
output: [{"a":1,"b":2},{}]

Boundary, reduced with a differential fuzzer + delta-shrinker, to [{"a":{}}]:
the container must be an array of objects, and a cell value must be an empty object {}.
A non-empty object value in the same position round-trips fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions