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

cmd/go: go list -json doesn't return valid JSON #59440

Closed
katiehockman opened this issue Apr 4, 2023 · 2 comments
Closed

cmd/go: go list -json doesn't return valid JSON #59440

katiehockman opened this issue Apr 4, 2023 · 2 comments

Comments

@katiehockman
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.19.5 darwin/arm64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

go list -json=ImportPath,Name,Imports ./...

What did you expect to see?

Commas after the closing curly brace, to allow for valid json parsing.

{
        "ImportPath": "...",
        "Name": "immutable"
},
{
        "ImportPath": "....",
        "Name": "pproflite",
        "Imports": [
                "fmt",
                "github.com/richardartoul/molecule",
                "github.com/richardartoul/molecule/src/codec",
                "io"
        ]
},
{
        "ImportPath": "...",
        "Name": "pprofutils",
        "Imports": [
                "bufio",
                "errors",
                "fmt",
                "github.com/google/pprof/profile",
                "io",
                "sort",
                "strconv",
                "strings",
                "time"
        ]
}

What did you see instead?

Invalid json that can't be parsed with json.Unmarshal (no commas after each }). Will get the following error: panic: invalid character '{' after top-level value

{
        "ImportPath": "...",
        "Name": "immutable"
}
{
        "ImportPath": "...",
        "Name": "pproflite",
        "Imports": [
                "fmt",
                "github.com/richardartoul/molecule",
                "github.com/richardartoul/molecule/src/codec",
                "io"
        ]
}
{
        "ImportPath": "...",
        "Name": "pprofutils",
        "Imports": [
                "bufio",
                "errors",
                "fmt",
                "github.com/google/pprof/profile",
                "io",
                "sort",
                "strconv",
                "strings",
                "time"
        ]
}

/cc @bcmills @jba

@katiehockman katiehockman changed the title cmd/go: go list -json doesn't give valid json cmd/go: go list -json doesn't return valid JSON Apr 4, 2023
@seankhliao
Copy link
Member

Duplicate of #12643 and many others
adding commas wouldn't make it valid, as it's not a list
json.Decoder works https://go.dev/play/p/KnmhmRnGmJt

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2023
@katiehockman
Copy link
Contributor Author

Gotcha, thanks @seankhliao 👍

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

No branches or pull requests

2 participants