Add JSON format for list outputs#6346
Conversation
|
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 Maybe we should write a spec for this. Just to think out loud about what I think we could do for the implementation...
|
|
Is there a reason the Microsoft.WinGet.Client PowerShell module isn't suitable for JSON output? I know several folks would like JSON output for WinGet, but generally that is because they want to build something that can use the JSON output like an API. We do have COM APIs, and we built the PowerShell module that is likely a better candidate for structured JSON output. |
This is answered in the linked issue by all the people asking for structured output. PowerShell is great but you are not delivering it as part of the system and having more outputs isn't going to bring too much of additional maintance. |
|
I would want the "shape" of the JSON to conform with the PowerShell objects in either case if we are going to go down this path. As @florelis suggested, we should probably have a specification so we can capture this consistently. I would also want some kind of telemetry event to inform us when folks are using the JSON output so we can understand the usage patterns better. We've been discussing internally something that could allow us to ship PowerShell in the packaged application, and we've reached out to the PowerShell team about how this might work and be extended to other packaged applications that also offer a PowerShell module. @SteveL-MSFT for visibility. |
📖 Description
Adds
--format jsonsupport for package listing output.This enables machine-readable output for:
winget list --format jsonwinget upgrade --format jsonwhen used in list-only modeThe 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 jsonis intentionally limited to non-mutating upgrade listing. Commands such aswinget upgrade --all --format jsonare rejected so package installation progress is not mixed with structured output.🔗 References
Related to #1753.
🔍 Validation
Added focused test coverage for:
--format json --help--detailswith JSON list outputRan the focused
AppInstallerCLITestsscenarios for the JSON list and upgrade flows locally.✅ Checklist
📋 Issue Type
Microsoft Reviewers: Open in CodeFlow