grafana/k6 · error

unable to convert response object to JSON: %w

Error message

unable to convert response object to JSON: %w

What it means

After a gRPC call, the response dynamic message could not be marshaled back to JSON by protojson. Dynamic messages do not map onto real Go types, so k6 round-trips them through JSON to make fields accessible from JS; this error means the response message itself violated protojson marshaling rules (e.g. an Any without a resolvable type). Fires after the RPC completes, during result conversion.

Source

Thrown at internal/lib/netext/grpcext/conn.go:199

		sterr := status.Convert(err)
		response.Status = sterr.Code()

		// (rogchap) when you access a JSON property in Sobek, you are actually accessing the underling
		// Go type (struct, map, slice etc); because these are dynamic messages the Unmarshaled JSON does
		// not map back to a "real" field or value (as a normal Go type would). If we don't marshal and then
		// unmarshal back to a map, you will get "undefined" when accessing JSON properties, even when
		// JSON.Stringify() shows the object to be correctly present.

		raw, _ := marshaler.Marshal(sterr.Proto())
		errMsg := make(map[string]any)
		_ = json.Unmarshal(raw, &errMsg)
		response.Error = errMsg
	}

	if resp != nil && !req.DiscardResponseMessage {
		msg, err := convert(marshaler, resp)
		if err != nil {
			return nil, fmt.Errorf("unable to convert response object to JSON: %w", err)
		}

		response.Message = msg
	}
	return &response, nil
}

// NewStream creates a new gRPC stream.
func (c *Conn) NewStream(
	ctx context.Context,
	req StreamRequest,
	opts ...grpc.CallOption,
) (*Stream, error) {
	ctx = metadata.NewOutgoingContext(ctx, req.Metadata)

	ctx = withRPCState(ctx, &rpcState{tagsAndMeta: req.TagsAndMeta})

	stream, err := c.raw.NewStream(ctx, &grpc.StreamDesc{

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Verify the server response matches the reflected proto schema, especially google.protobuf.Any fields that need resolvable type URLs
  2. Ensure the Client was created from a reflection-capable server so all types in the response are known
  3. If the schema uses uncommon well-known types, load the proto definitions from a local bundle instead of reflection
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/lib/netext/grpcext/conn.go:199 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/87b8dbd49a155c04. Report an issue: GitHub.