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: use "go list -json" list two or more packages won't get correct json output #12643

Closed
m3ng9i opened this issue Sep 16, 2015 · 1 comment

Comments

@m3ng9i
Copy link

m3ng9i commented Sep 16, 2015

I use the following command to list information of two packages:

go list -json builtin container/ring

Then I got the result:

{
        "Dir": "D:\\go\\go1.5.1\\src\\builtin",
        "ImportPath": "builtin",
        "Name": "builtin",
        "Doc": "Package builtin provides documentation for Go's predeclared identifiers.",
        "Target": "D:\\go\\go1.5.1\\pkg\\windows_386\\builtin.a",
        "Goroot": true,
        "Standard": true,
        "Stale": true,
        "Root": "D:\\go\\go1.5.1",
        "GoFiles": [
                "builtin.go"
        ],
        "Deps": [
                "runtime",
                "unsafe"
        ]
}
{
        "Dir": "D:\\go\\go1.5.1\\src\\container\\ring",
        "ImportPath": "container/ring",
        "Name": "ring",
        "Doc": "Package ring implements operations on circular lists.",
        "Target": "D:\\go\\go1.5.1\\pkg\\windows_386\\container\\ring.a",
        "Goroot": true,
        "Standard": true,
        "Root": "D:\\go\\go1.5.1",
        "GoFiles": [
                "ring.go"
        ],
        "Deps": [
                "runtime",
                "unsafe"
        ],
        "TestGoFiles": [
                "ring_test.go"
        ],
        "TestImports": [
                "fmt",
                "testing"
        ]
}

You can see, the format of the result is:

{
    ...
}
{
    ...
}

not:

[{
    ...
},
{
    ...
}]

There miss a comma and a pair of square brackets, so the json decorder cannot decorde the output.

My go version: go1.5.1 windows/386

@bradfitz
Copy link
Contributor

Sorry, but this isn't something we can change at this point for compatibility reasons.

Note that Go's and other JSON decoders will let you decode multiple JSON objects from a stream in a row, ignoring whitespace. It's not a valid single JSON value (not an array) but it's valid multiple JSON values.

@golang golang locked and limited conversation to collaborators Sep 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants