golang/go · error

parsing JSON diagnostics: %v

Error message

parsing JSON diagnostics: %v

What it means

A JSON tree entry whose value starts with '[' (the []Diagnostic array form) failed to unmarshal into []jsonDiagnostic. The %v is the unmarshal error.

Source

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

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)
					}

					base.SetExitStatus(1)
					return errors.New(e.Err)
				}
			}
		}
	}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Update the analyzer to match golang.org/x/tools/go/analysis/unitchecker's Diagnostic JSON schema
  2. Pin analyzer and toolchain versions together
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: The analyzer's per-analyzer value is shaped like an array but elements don't match the jsonDiagnostic schema (e.g. missing required fields, wrong types).

Common situations: Analyzer emitting a non-standard diagnostic schema; version skew between cmd/go's expected jsonDiagnostic fields and the analyzer output.

Related errors


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