go Verified current stable Not installed? Programming

Go / List Packages Json

List Packages Json

Outputs specified Go packages and their metadata in JSON format.

$
Terminal
go list -json time net/http

When To Use

For automated tools or scripts that require package dependency information in machine-readable format.

Pro Tip

Use ` -e` option to ensure that undefined dependencies don’t halt your script.

Anatomy of Output

Understanding the result

{"Path":"time","Version":"v0.0.0-20230822143036-cace12345678","Dir":"/usr/local/go/pkg/mod/time@v0.0.0-20230822143036-cace12345678"} JSON Output

Describes the package path, version, and directory.

Power User Variants

Optimized versions

go list -json all

Outputs all package data in JSON format.

go list -json ./...

Lists all local packages in the current module.

Troubleshooting

Common pitfalls

go: no such package: time

Solution: Check that the package name is correct or that it exists.

invalid JSON format

Solution: Ensure the command syntax and flags are correct.

go: cannot find module providing package net/http

Solution: Make sure to have Go modules enabled for the specific version.

Command Breakdown

What each part is doing

go
Base Command
The executable that performs this operation. Here it runs Go before the shell applies any redirect operators.
-json
Command Option
Tool-specific option used by this command invocation.

Alternative Approaches

Comparable commands in other tools

Alternative programming tools for the same job.