nektos/act · error

Cannot parse non-string type %v as JSON

Error message

Cannot parse non-string type %v as JSON

What it means

Thrown by fromJSON() when its argument is not reflect.String. GitHub's fromJSON only accepts a JSON string; passing a number, boolean, array, or object value directly is rejected before parsing.

Source

Thrown at pkg/exprparser/functions.go:170

	}
}

func (impl *interperterImpl) toJSON(value reflect.Value) (string, error) {
	if value.Kind() == reflect.Invalid {
		return "null", nil
	}

	json, err := json.MarshalIndent(value.Interface(), "", "  ")
	if err != nil {
		return "", fmt.Errorf("Cannot convert value to JSON. Cause: %v", err)
	}

	return string(json), nil
}

func (impl *interperterImpl) fromJSON(value reflect.Value) (interface{}, error) {
	if value.Kind() != reflect.String {
		return nil, fmt.Errorf("Cannot parse non-string type %v as JSON", value.Kind())
	}

	var data interface{}

	err := json.Unmarshal([]byte(value.String()), &data)
	if err != nil {
		return nil, fmt.Errorf("Invalid JSON: %v", err)
	}

	return data, nil
}

func (impl *interperterImpl) hashFiles(paths ...reflect.Value) (string, error) {
	var ps []gitignore.Pattern

	const cwdPrefix = "." + string(filepath.Separator)
	const excludeCwdPrefix = "!" + cwdPrefix
	for _, path := range paths {

View on GitHub (pinned to 4f41128141)

Solutions

  1. Only pass strings to fromJSON; for already-object values just use them directly.
  2. Fix the input's declared type (string instead of number/boolean) in workflow_dispatch inputs.
  3. Use toJSON() when you need the opposite direction.
  4. Wrap non-strings: pass the raw JSON text, not a parsed structure.

Example fix

# before
inputs:
  cfg:
    type: number
...
${{ fromJSON(inputs.cfg) }}
# after
inputs:
  cfg:
    type: string
...
${{ fromJSON(inputs.cfg) }}
Defensive patterns

Strategy: type-guard

Type guard

func isStringy(v interface{}) bool {
  return reflect.TypeOf(v) == nil || reflect.TypeOf(v).Kind() == reflect.String
}

Try / catch

if v, err := fromJSON(x); err != nil {
  if strings.Contains(err.Error(), 'non-string') {
    // already structured data: use as-is instead of parsing
    return x
  }
  return err
}

Prevention

When it happens

Trigger: fromJSON(inputs.myjson) where the input was declared type: number (so it arrives as a number); fromJSON(github.event.pull_request) which is already an object; double conversion fromJSON(fromJSON(x)).

Common situations: Workflow inputs typed incorrectly in workflow_dispatch inputs; assuming fromJSON also serializes (use toJSON for that); data already parsed upstream.

Related errors


AI-assisted analysis of nektos/act@4f41128141 (2026-08-15). Data as JSON: /api/errors/9792b6852e4078c1. Report an issue: GitHub.