Skip to content

Add JSON format for list outputs#6346

Open
PrzemyslawKlys wants to merge 9 commits into
microsoft:masterfrom
PrzemyslawKlys:feature/list-upgrade-json-format
Open

Add JSON format for list outputs#6346
PrzemyslawKlys wants to merge 9 commits into
microsoft:masterfrom
PrzemyslawKlys:feature/list-upgrade-json-format

Conversation

@PrzemyslawKlys

@PrzemyslawKlys PrzemyslawKlys commented Jul 3, 2026

Copy link
Copy Markdown

📖 Description

Adds --format json support for package listing output.

This enables machine-readable output for:

  • winget list --format json
  • winget upgrade --format json when used in list-only mode

The default table output is unchanged.

The JSON output includes installed package fields that match the existing list and upgrade table data, including package name, id, installed version, available version, and source. It also keeps JSON parseable for empty results and common error paths such as source-open failures, WinGet policy blocks, and generic execution failures.

winget upgrade --format json is intentionally limited to non-mutating upgrade listing. Commands such as winget upgrade --all --format json are rejected so package installation progress is not mixed with structured output.

🔗 References

Related to #1753.

🔍 Validation

Added focused test coverage for:

  • JSON list output
  • JSON upgrade-list output
  • empty result output
  • settings warnings before JSON output
  • source-open failures
  • WinGet policy blocks
  • generic execution failures
  • preserving help output for --format json --help
  • rejecting JSON output for unsupported upgrade execution modes
  • rejecting --details with JSON list output

Ran the focused AppInstallerCLITests scenarios for the JSON list and upgrade flows locally.

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

@PrzemyslawKlys
PrzemyslawKlys requested a review from a team as a code owner July 3, 2026 07:21
@florelis

Copy link
Copy Markdown
Member

I don't think this implementation would scale well for extending it to the rest of the flows. As it is, any time we did any output, we would have to add a check for if we want JSON and do something different. I would prefer this to be handled in the Reporter as much as possible. For the tables in particular, the TableOutput could be extended to handle the output to JSON.

Maybe we should write a spec for this. Just to think out loud about what I think we could do for the implementation...

  • We need to create schemas for all the objects we want to output, because people will definitely take a dependency on it and we can't break them later.
  • We can add a flag to the reporter to tell it whether the output has to be text or JSON (or any other thing in the future)
  • We would generally move away from passing strings directly to the reporter, and instead pass it objects that it knows how to format for each case. We would still output strings directly, but those would be more decorative (for example, "Installation succeeded" at the end) and the reporter would just discard them if it is using JSON.
    For example, for errors, we would pass an "error" object with an HResult and a message. For JSON it would add that as an object. For normal output it would print just the message. And then in both cases throw the HResult
  • This would be too big to do in a single PR. We would add --format as an experimental argument, and then convert the output over time. If we set a flag in the Reporter to discard all normal strings when using JSON, it would initially return nothing for all commands, which I think could be a good default until we implement each one.

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