golang/go · error

parsing JSON: %v

Error message

parsing JSON: %v

What it means

printJSONDiagnostics could not json.Unmarshal the tool's entire stdout into a jsonTree (map[PackageID]map[AnalyzerName]json.RawMessage). The %v is the json.SyntaxError / UnmarshalTypeError. Fires only with -json analyzers.

Source

Thrown at src/cmd/go/internal/vet/vet.go:383

		base.SetExitStatus(1)
	}
	return nil
}

// printJSONDiagnostics parses JSON (from the tool's stdout) and
// prints it (to stderr) in "file:line: message" form.
// It also ensures that we exit nonzero if there were diagnostics.
func printJSONDiagnostics(r io.Reader) error {
	stdout, err := io.ReadAll(r)
	if err != nil {
		return err
	}
	if len(stdout) > 0 {
		// unitchecker emits a JSON map of the form:
		// output maps Package ID -> Analyzer.Name -> (error | []Diagnostic);
		var tree jsonTree
		if err := json.Unmarshal(stdout, &tree); err != nil {
			return fmt.Errorf("parsing JSON: %v", err)
		}
		for _, units := range tree {
			for analyzer, msg := range units {
				if msg[0] == '[' {
					// []Diagnostic
					var diags []jsonDiagnostic
					if err := json.Unmarshal([]byte(msg), &diags); err != nil {
						return fmt.Errorf("parsing JSON diagnostics: %v", err)
					}
					for _, diag := range diags {
						base.SetExitStatus(1)
						printJSONDiagnostic(analyzer, diag)
					}
				} else {
					// error
					var e jsonError
					if err := json.Unmarshal([]byte(msg), &e); err != nil {
						return fmt.Errorf("parsing JSON error: %v", err)

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Run the analyzer standalone with -json and validate its output with jq
  2. Ensure the analyzer uses golang.org/x/tools/go/analysis/unitchecker and emits map[PackageID]map[AnalyzerName]string
  3. Separate stdout (JSON) from stderr (logs)
Defensive patterns

Strategy: validation

Validate before calling

// Validate analyzer JSON shape before trusting it
func validJSONTree(b []byte) error {
  var t map[string]map[string]json.RawMessage
  return json.Unmarshal(b, &t)
}

Prevention

When it happens

Trigger: An analyzer invoked with -json emitted malformed or non-JSON output, or crashed mid-output printing a partial object, so the top-level unmarshal fails.

Common situations: Custom analyzer not implementing the unitchecker JSON contract; analyzer stderr leaking into stdout; tool segfault mid-stream; version skew between cmd/go's expected schema and the analyzer.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/99838eaa85277751. Report an issue: GitHub.