goharbor/harbor · error

empty json data to parse

Error message

empty json data to parse

What it means

Returned by scan-export Request.FromJSON when the input string is empty. The export request model (harbor repositories, tags, CVE ids, projects lists) is deserialized from a JSON string carried in job parameters; an empty payload is rejected before json.Unmarshal.

Source

Thrown at src/pkg/scan/export/model.go:69

	CVEIds string

	// A list of one or more labels for which to export the scan data, defaults to all if empty
	Labels []int64

	// A list of one or more projects for which to export the scan data, defaults to all if empty
	Projects []int64

	// A list of repositories for which to export the scan data, defaults to all if empty
	Repositories string

	// A list of tags for which to export the scan data, defaults to all if empty
	Tags string
}

// FromJSON parses robot from json data
func (c *Request) FromJSON(jsonData string) error {
	if len(jsonData) == 0 {
		return errors.New("empty json data to parse")
	}

	return json.Unmarshal([]byte(jsonData), c)
}

// ToJSON marshals Robot to JSON data
func (c *Request) ToJSON() (string, error) {
	data, err := json.Marshal(c)
	if err != nil {
		return "", err
	}

	return string(data), nil
}

// Execution provides details about the running status of a scan data export job
type Execution struct {
	// ID of the execution

View on GitHub (pinned to 7b2fd08cc5)

Solutions

  1. Ensure the export job parameters contain the serialized request JSON before submitting the job
  2. Validate len(params) payload at the API boundary and reject with BAD_REQUEST there
  3. Re-create the export request via the UI/API if the job was corrupted

Example fix

// before
var req export.Request
err := req.FromJSON("")

// after
jsonData := params[JobParamRequest].(string)
if len(jsonData) == 0 {
    return errors.New("export request payload is required")
}
err := req.FromJSON(jsonData)
Defensive patterns

Strategy: validation

Validate before calling

if len(jsonData) == 0 {
    return errors.New("export request JSON payload is required")
}
var req export.Request
if err := req.FromJSON(jsonData); err != nil {
    return err
}

Prevention

When it happens

Trigger: Launching an export scan-data job whose job parameters omit the request JSON; passing an empty string from the API layer to the job; job parameters truncated during job re-enqueue.

Common situations: API clients posting the export request body as empty; job service replaying old jobs with missing params; integration code building job.Parameters map without the request key.

Related errors


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/df70dfe144e13389. Report an issue: GitHub.