Skip to content

--format table silently drops fields that are not present on the first array item #46

Description

@dumanoglu1

Bug

--format table derives its columns from only the first object in an array. If later rows contain additional fields, those values are silently omitted from the table output.

In src/output.ts:

const keys = Object.keys(data[0] as Record<string, unknown>)

That works for homogeneous arrays, but OpenSea API responses can include optional fields that differ between items. In that case the CLI makes the later-row data look absent even though it is present in the JSON response.

Reproduction

formatOutput(
  [
    { name: "CryptoPunk #1", price: "10 ETH" },
    { name: "Bored Ape #2", price: "5 ETH", rarity: "Rare" },
  ],
  "table",
)

Expected: the table includes a rarity column and shows Rare on the second row.

Actual: the table only includes name and price, because rarity is not present on the first item.

Suggested fix

Build the table header from the union of keys across all object rows, preserving first-seen order. Homogeneous arrays keep the same output, while heterogeneous arrays no longer lose later-row fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions