Skip to content

An empty Starlark list in a command result marshals as null, not [] #825

Open

Description

@David-Noble-at-work

Feature: #461 — The star CLI: commands and file processing

goValue in cmd/star/star/result.go converts a Starlark list to a Go slice. An empty list
becomes a nil slice, which encoding/json marshals as null, not [].

Observed

A row built in Starlark as {"faults": []} renders under -o json as "faults": null. A consumer
doing .faults | length in jq gets 0 either way, but one testing .faults == [] or iterating in a
typed language sees a different value than the script produced. The same value from
Get-EpicReport's jq is [].

Fix

Allocate with make([]any, 0, n) rather than a nil var, so the empty case marshals as []. Same
for an empty dict, if it has the same shape ({} vs null).

Observed under noblefactor-ops#140 Phase 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Epic:StarlarkSurfaceThe Starlark authoring surfacebugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions