Skip to content

Fix empty JSON output to return "[]" instead of "{}" - #560

Open
ampandey-hub wants to merge 1 commit into
RedHatInsights:mainfrom
ampandey-hub:fix/empty-json-array-output
Open

Fix empty JSON output to return "[]" instead of "{}"#560
ampandey-hub wants to merge 1 commit into
RedHatInsights:mainfrom
ampandey-hub:fix/empty-json-array-output

Conversation

@ampandey-hub

Copy link
Copy Markdown

When no data collectors are configured, 'rhc collector list --format json'
and 'rhc collector timers --format json' output {} (empty JSON object).
Since collectors are a list, the correct empty value is [] (empty array).

Fix:

Changed two locations that explicitly print {} to print [] instead:

  • cmd/rhc/collector_cmd.gocollectorListAction
  • internal/ui/collector.goprintMachineReadable

How I tested

  1. Built rhc and rhc-server from source on RHEL 10 (x86_64)
  2. Started rhc-server with an empty /usr/lib/rhc/collectors/ directory
  3. Before fix: rhc collector list --format json → {}
  4. Before fix: rhc collector timers --format json → {}
  5. After fix: rhc collector list --format json → []
  6. After fix: rhc collector timers --format json → []

Resolves: RHEL-216725

@Archana-PandeyM

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! The CI is currently failing because the commit message is missing the conventional commit category/type (fix:, feat:, test:, etc.).

Could you please amend the commit message to something like:

fix: return empty JSON array for collector list

Once updated, the commit-pipeline check should pass.
to learn about conventional commit https://www.conventionalcommits.org/en/v1.0.0/

@Archana-PandeyM

Copy link
Copy Markdown
Collaborator

/packit test

@Archana-PandeyM

Copy link
Copy Markdown
Collaborator

/packit build

@Archana-PandeyM
Archana-PandeyM self-requested a review August 21, 2026 15:50
When no data collectors are configured, 'rhc collector list --format json'
and 'rhc collector timers --format json' output {} (empty JSON object).
Since collectors are a list, the correct empty value is [] (empty array).

Resolves: RHEL-216725
Signed-off-by: Aman Pandey <ampandey@redhat.com>
@ampandey-hub
ampandey-hub force-pushed the fix/empty-json-array-output branch from 468022f to fa70149 Compare August 22, 2026 08:26
@Archana-PandeyM

Copy link
Copy Markdown
Collaborator

/packit build

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants