Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list option to format output as json #2032

Closed
MrDRamos opened this issue Mar 20, 2022 · 10 comments
Closed

Add list option to format output as json #2032

MrDRamos opened this issue Mar 20, 2022 · 10 comments
Labels
Issue-Feature This is a feature request for the Windows Package Manager client.
Milestone

Comments

@MrDRamos
Copy link

Description of the new feature / enhancement

The list command outputs a human readable table of installed packages that is not easy to parse by an external tool. Formatting the list output as JSON by adding a --JsonOutput command line option would be very useful.

Proposed technical implementation details

No response

@MrDRamos MrDRamos added the Issue-Feature This is a feature request for the Windows Package Manager client. label Mar 20, 2022
@ghost ghost added the Needs-Triage Issue need to be triaged label Mar 20, 2022
@denelon denelon removed the Needs-Triage Issue need to be triaged label Mar 21, 2022
@denelon
Copy link
Contributor

denelon commented Mar 21, 2022

We've discussed having "--json" as an argument to do exactly this, but hadn't created an issue for it :)

@MiroslavMikus
Copy link

I am playing with it right now and thought how good it would be to have the --json parameter.
For someone having the same problem right now -> Here is a nice Powershell script which can parse the output to a custom object. Just be aware that the table heders are important and they are OS language-dependent 😄

@WillPittenger
Copy link

It's strange a --as-yaml option wasn't baked into winget search and winget show from day one. Just spit out the YAML as you get it. The existing system almost seems designed to make parsing impossible. How much work would be needed to implement either YAML or JSON output?

@denelon
Copy link
Contributor

denelon commented May 25, 2022

@WillPittenger we've been open source since the very first preview in 2020. There has been a mixture of priorities, and the overall roadmap philosophy is shared. This simply wasn't something the community wanted as a top priority.

Looking at the top-most 👍Issues:

Supporting PowerShell as a native interface will expose rich objects for many of the scripted/automated scenarios being asked for by many IT Professionals, as well as many developers and power users. We've been considering exposing the CLI output as JSON as an additional value add since most of the work would have to be done in order to support a native PowerShell experience.

@MrDRamos
Copy link
Author

I agree 100% with PowerShell support! The reason JSON output was requested is because it is readily consumed by PowerShell.

@Romanitho
Copy link

JSON output would be much easier for our projects. Scripts would become much simpler 😇

@CoryG89
Copy link

CoryG89 commented Jan 17, 2023

Not sure if everyone is aware of this already or not, but for those that are looking to get winget results in JSON format, I was looking for the same and came upon the winget.run REST API which serves my purposes fine for now until winget itself is able to provide this functionality.

For my own use case, I only needed JSON for search results rather than for installed packages, so in my case just directly using the API alone satisfies my needs, but it could also potentially be useful for those looking to get JSON for installed packages as well if you're willing to jump through an additional hoop. The API doesn't know what packages you have installed, but if you use the winget cli itself to get just a list of your installed package ids, you can then pass those ids directly into the winget.run API which will get you the JSON for all of your installed packages.

Not ideal, but perhaps this may be helpful for some others until the eventual time when the winget cli will inevitably satisfy all of these use cases itself once further development is completed.

https://docs.winget.run/docs/introduction/

https://github.com/winget-run/wingetdotrun

EDIT: Oops, someone pointed out to me that this may be problematic for getting JSON for installed packages as there seems to be no way to actually pass in more than one package id with a single call to the API. Sorry about that.

@alexandair
Copy link

Instead of --json or --jsonoutput, I would suggest implementing --output that can accept json as a value and maybe some other values in the future. Just how Azure CLI does today.

Trasen added a commit to Trasen/SubprocessAbstraction that referenced this issue Feb 13, 2023
Winget has a different type of error-code structure, and lacks any kind of "export as data" functionality. Hopefully this changes in the future, letting us get more information from the cli api (microsoft/winget-cli#2032)
@cezarypiatek
Copy link

cezarypiatek commented Aug 8, 2023

If you need to process data returned from the winget cli output, you can use Microsoft.WinGet.Client powershell package

https://github.com/microsoft/winget-cli/blob/master/src/PowerShell/Microsoft.WinGet.Client/README.md

example usage:

# Install module for winget
Install-Package Microsoft.WinGet.Client


# Show All installed packages
Get-WinGetPackage | Out-GridView

@Trenly Trenly mentioned this issue Aug 12, 2023
@denelon
Copy link
Contributor

denelon commented Mar 6, 2024

In addition to the PowerShell module, COM APIs are also available for object-based integration.

@denelon denelon closed this as completed Mar 6, 2024
@denelon denelon added this to the 1.8 Client milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Feature This is a feature request for the Windows Package Manager client.
Projects
None yet
Development

No branches or pull requests

8 participants