grafana/k6 · error

json couldn't be parsed: %w

Error message

json couldn't be parsed: %w

What it means

parseAndEmitWebVitalMetric could not json.Unmarshal the string received from the page's web-vitals binding into the expected structure. The payload from the browser didn't match the expected JSON shape — an internal contract mismatch between the injected web-vitals script and k6.

Source

Thrown at internal/js/modules/k6/browser/common/frame_session.go:355

}

func (fs *FrameSession) parseAndEmitWebVitalMetric(object string) error {
	fs.logger.Debugf("FrameSession:parseAndEmitWebVitalMetric", "object:%s", object)

	wv := struct {
		ID             string
		Name           string
		Value          json.Number
		Rating         string
		Delta          json.Number
		NumEntries     json.Number
		NavigationType string
		URL            string
		SpanID         string
	}{}

	if err := json.Unmarshal([]byte(object), &wv); err != nil {
		return fmt.Errorf("json couldn't be parsed: %w", err)
	}

	metric, ok := fs.k6Metrics.WebVitals[wv.Name]
	if !ok {
		return fmt.Errorf("metric not registered %q", wv.Name)
	}

	value, err := wv.Value.Float64()
	if err != nil {
		return fmt.Errorf("value couldn't be parsed %q", wv.Value)
	}

	state := fs.vu.State()
	tags := state.Tags.GetCurrentValues().Tags
	if state.Options.SystemTags.Has(k6metrics.TagURL) {
		tags = handleURLTag(fs.page, wv.URL, http.MethodGet, tags)
	}

View on GitHub (pinned to 94169daab2)

Solutions

  1. Update k6 — the injected web-vitals script and parser must stay in sync
  2. Report to grafana/k6 if it persists, including the page URL
  3. Retry; corrupted payloads under heavy load are rare but possible
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/frame_session.go:355 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@94169daab2 (2026-08-18). Data as JSON: /api/errors/6172c07d2f931e1d. Report an issue: GitHub.