nektos/act · error
Cannot convert value to JSON. Cause: %v
Error message
Cannot convert value to JSON. Cause: %v
What it means
Thrown by the expression toJSON() function when json.MarshalIndent fails on the value. Common causes: the value contains a channel, func, complex number, or a cyclic data structure that Go's json package cannot serialize.
Source
Thrown at pkg/exprparser/functions.go:162
var items []string
for i := 0; i < array.Len(); i++ {
items = append(items, impl.coerceToString(array.Index(i).Elem()).String())
}
return strings.Join(items, separator), nil
default:
return strings.Join([]string{impl.coerceToString(array).String()}, separator), nil
}
}
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, nilView on GitHub (pinned to 4f41128141)
Solutions
- Check the %v cause in the message — 'unsupported type' names the offending type.
- toJSON a narrower sub-object (e.g. toJSON(inputs.x) instead of toJSON(inputs)).
- In custom Go usage, pre-convert funcs/channels or use json.RawMessage.
- Verify the value is plain data (maps/slices/strings/numbers/bools).
Example fix
# before
${{ toJSON(github.event) }}
# after (narrow to the needed part)
${{ toJSON(github.event.commits[0].author) }} Defensive patterns
Strategy: try-catch
Type guard
func isJSONSerializable(v interface{}) bool {
switch reflect.TypeOf(v).Kind() {
case reflect.Chan, reflect.Func, reflect.UnsafePointer, reflect.Complex64, reflect.Complex128:
return false
}
_, err := json.Marshal(v)
return err == nil
} Try / catch
if s, err := toJSON(v); err != nil {
if strings.Contains(err.Error(), 'Cannot convert value to JSON') {
s = fmt.Sprintf('%v', v) // degrade to plain rendering
} else { return err }
} Prevention
- Keep context values to plain data types
- toJSON narrow sub-objects rather than whole contexts
- In Go, replace funcs/channels before injecting env
When it happens
Trigger: toJSON(someContextField) where the mapped context value, after act's env conversion, ends up as an unmarshalable Go type; rarely, deeply nested structures hitting encoder limits.
Common situations: Calling toJSON() on unusual contexts; values derived from fromJSON round-trips; custom Go code embedding non-serializable fields into the expression environment.
Related errors
- The following format string is invalid: '%s'
- The following format string references more arguments than w
- Unclosed brackets. The following format string is invalid: '
- Closing bracket without opening one. The following format st
- Cannot parse non-string type %v as JSON
AI-assisted analysis of nektos/act@4f41128141 (2026-08-15).
Data as JSON: /api/errors/bef48a16f20df183.
Report an issue: GitHub.