{"record":{"id":"ec883b7a618fe893","repo":"ory/kratos","slug":"boolean-unmarshal-error-invalid-input-s","errorCode":null,"errorMessage":"boolean unmarshal error: invalid input %s","messagePattern":"boolean unmarshal error: invalid input (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/json_bool.go","lineNumber":21,"sourceCode":"\npackage x\n\nimport (\n\t\"fmt\"\n)\n\n// ConvertibleBoolean can unmarshal both booleans and strings.\ntype ConvertibleBoolean bool\n\nfunc (bit *ConvertibleBoolean) UnmarshalJSON(data []byte) error {\n\tasString := string(data)\n\tswitch asString {\n\tcase \"true\", `\"true\"`:\n\t\t*bit = true\n\tcase \"false\", `\"false\"`:\n\t\t*bit = false\n\tdefault:\n\t\treturn fmt.Errorf(\"boolean unmarshal error: invalid input %s\", asString)\n\t}\n\treturn nil\n}\n","sourceCodeStart":3,"sourceCodeEnd":25,"githubUrl":"https://github.com/ory/kratos/blob/b86338da04a040247a07f46100a86dcfb3875909/x/json_bool.go#L3-L25","documentation":"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.","triggerScenarios":"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\").","commonSituations":"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.","solutions":["Change the JSON value to true/false (or the quoted strings \"true\"/\"false\").","If the source emits 0/1 integers, preprocess the JSON or use a custom wrapper type that accepts integers.","Normalize casing to lowercase before unmarshaling (\"True\" → \"true\").","Check the exact input echoed in the message for hidden whitespace or encoding issues."],"exampleFix":"// before\n{\"verify\": 1}\n// after\n{\"verify\": true}","handlingStrategy":"validation","validationCode":"func isParseableBool(v interface{}) bool {\n    switch x := v.(type) {\n    case bool:\n        return true\n    case string:\n        return x == \"true\" || x == \"false\" || x == `\"true\"` || x == `\"false\"`\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"var payload struct{ Verify Bool } \nif err := json.Unmarshal(data, &payload); err != nil && strings.Contains(err.Error(), \"boolean unmarshal error\") {\n    log.Warn(\"non-boolean value in bool field\", \"err\", err)\n}","preventionTips":["Ensure producers emit JSON true/false, not 1/0 or \"yes\".","Use lowercase string values if strings are required.","Check third-party payloads for numeric booleans and preprocess them."],"tags":["json","unmarshal","boolean","type-conversion"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"b86338da04a040247a07f46100a86dcfb3875909","analyzedAt":"2026-09-07T15:58:15.934Z","contentChangedAt":"2026-09-07T15:58:15.934Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}