ory/kratos · error

boolean unmarshal error: invalid input

Error message

boolean unmarshal error: invalid input %s

What it means

x/json_bool.go implements a custom UnmarshalJSON for a boolean type that accepts "true", "false", and their JSON-string variants. Any other input — numbers like 1/0, empty strings, or malformed values — is rejected with this error because the library deliberately does not coerce arbitrary JSON values to booleans.

Solutions

  1. Change the JSON value to true/false (or the quoted strings "true"/"false").
  2. If the source emits 0/1 integers, preprocess the JSON or use a custom wrapper type that accepts integers.
  3. Normalize casing to lowercase before unmarshaling ("True" → "true").
  4. Check the exact input echoed in the message for hidden whitespace or encoding issues.

Example fix

// before
{"verify": 1}
// after
{"verify": true}
Defensive patterns

Strategy: validation

Validate before calling

func isParseableBool(v interface{}) bool {
    switch x := v.(type) {
    case bool:
        return true
    case string:
        return x == "true" || x == "false" || x == `"true"` || x == `"false"`
    }
    return false
}

Try / catch

var payload struct{ Verify Bool } 
if err := json.Unmarshal(data, &payload); err != nil && strings.Contains(err.Error(), "boolean unmarshal error") {
    log.Warn("non-boolean value in bool field", "err", err)
}

Prevention

When it happens

Trigger: Unmarshaling JSON into a struct containing the json_bool/boolean wrapper type where the field value is 1, 0, "yes", "", null-ish, or a string with different casing ("True").

Common situations: Consuming third-party API responses that encode booleans as 0/1 integers; config files using "on"/"off" or "True"; hand-written JSON fixtures with numeric booleans.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of ory/kratos@b86338da04 (2026-09-07). Data as JSON: /api/errors/ec883b7a618fe893. Report an issue: GitHub.

Appendix: source

Thrown at x/json_bool.go:21

package x

import (
	"fmt"
)

// ConvertibleBoolean can unmarshal both booleans and strings.
type ConvertibleBoolean bool

func (bit *ConvertibleBoolean) UnmarshalJSON(data []byte) error {
	asString := string(data)
	switch asString {
	case "true", `"true"`:
		*bit = true
	case "false", `"false"`:
		*bit = false
	default:
		return fmt.Errorf("boolean unmarshal error: invalid input %s", asString)
	}
	return nil
}

View on GitHub (pinned to b86338da04)