use the strconv package

docs

strconv.FormatBool(v)

func FormatBool(b bool) string FormatBool returns "true" or "false"
according to the value of b

Answer from Brrrr on Stack Overflow
🌐
Educative
educative.io › answers › how-to-use-the-strconvparsebool-function-in-golang
How to use the strconv.ParseBool() function in Golang
The ParseBool() function returns the value in the boolean form represented by the string that is provided. It belongs to a strconv package. It only accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, and False.
🌐
Go Packages
pkg.go.dev › strconv
strconv package - strconv - Go Packages
ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
Discussions

type conversion - How to convert a bool to a string in Go? - Stack Overflow
I am trying to convert a bool called isExist to a string (true or false) by using string(isExist) but it does not work. What is the idiomatic way to do this in Go? More on stackoverflow.com
🌐 stackoverflow.com
Parse a boolean value represented by string logically
The transforming specification in Go standard library's strconv.ParseBool() is good for it. More on github.com
🌐 github.com
21
November 23, 2023
go - Parse parameter to bool or just use string in switch statement - Stack Overflow
I'm coming across a few situations where I would like to use routing to change some Is_Active fields in my database but I'm curious about performance. Let's have a route handler as so: func testH... More on stackoverflow.com
🌐 stackoverflow.com
types - Is there a way to convert integers to bools in go or vice versa? - Stack Overflow
Is there a builtin way to cast bools to integers or vice versa? I've tried normal casting, but since they use different underlying types, conversion isn't possible the classic way. I've poured over... More on stackoverflow.com
🌐 stackoverflow.com
🌐
gosamples
gosamples.dev › tutorials › convert string to bool in go
🔟 Convert string to bool in Go
September 30, 2021 - To convert a string to a bool in Go, use strconv.ParseBool() function from the strconv package. It takes one of the accepted string values: "1", "t", "T", "TRUE", "true", "True", "0", "f", "F", "FALSE", "false", "False" and converts it to the equivalent boolean value: true or false.
🌐
Dot Net Perls
dotnetperls.com › convert-string-bool-go
Go - Convert String to Bool: strconv.ParseBool - Dot Net Perls
May 24, 2021 - In Go we use the strconv package to convert types like bool and strings. We can use ParseBool to get a bool from a string.
🌐
ZetCode
zetcode.com › golang › strconv-parsebool
Using strconv.ParseBool in Go
April 20, 2025 - The strconv.ParseBool function converts a string to a boolean value.
🌐
IncludeHelp
includehelp.com › golang › strconv-parsebool-function-with-examples.aspx
Golang strconv.ParseBool() Function with Examples
September 7, 2021 - The return type of the ParseBool() function is (bool, error), it returns the boolean value represented by the string. // Golang program to demonstrate the // example of strconv.ParseBool() Function package main import ( "fmt" "strconv" ) func main() { fmt.Println(strconv.ParseBool("true")) fmt.Println(strconv.ParseBool("True")) fmt.Println(strconv.ParseBool("TRUE")) fmt.Println(strconv.ParseBool("t")) fmt.Println(strconv.ParseBool("T")) fmt.Println(strconv.ParseBool("1")) fmt.Println() fmt.Println(strconv.ParseBool("false")) fmt.Println(strconv.ParseBool("False")) fmt.Println(strconv.ParseBool("FALSE")) fmt.Println(strconv.ParseBool("f")) fmt.Println(strconv.ParseBool("F")) fmt.Println(strconv.ParseBool("0")) }
🌐
Rez Moss
rezmoss.com › blog › parsing-booleans-integers-go-parsebool-parseint-p2-7
Parsing Booleans and Integers in Go: ParseBool, ParseInt, and ParseUint 2/7 - Rez Moss
August 30, 2025 - The function is strict about its input validation. Any string that doesn’t match the accepted patterns will return an error of type *strconv.NumError. This makes ParseBool reliable but requires you to handle cases where the input might not conform to these specific formats.
Find elsewhere
🌐
Admfactory
admfactory.com › home › how to convert a string to a boolean type in golang
How to convert a string to a boolean type in Golang | ADMFactory
package main import ( "fmt" "strconv" ) func main() { b, err := strconv.ParseBool("false") if err == nil { /** displayg the type of the b variable */ fmt.Printf("Type: %T \n", b) /** displaying the string variable into the console */ fmt.Println("Value:", b) } }
🌐
HotExamples
golang.hotexamples.com › examples › strconv › - › ParseBool › golang-parsebool-function-examples.html
Golang ParseBool Examples, strconv.ParseBool Golang Examples - HotExamples
// GetProfileSearchOptions fetches the options in the querystring that are being // used to filter and search for profiles func GetProfileSearchOptions(query url.Values) ProfileSearchOptions { so := ProfileSearchOptions{} if query.Get("top") != "" { inTop, err := strconv.ParseBool(query.Get("top")) if err == nil { so.OrderByCommentCount = inTop } } if query.Get("q") != "" { startsWith := strings.TrimLeft(query.Get("q"), "+@") if startsWith != "" { so.StartsWith = startsWith } } if query.Get("following") != "" { inFollowing, err := strconv.ParseBool(query.Get("following")) if err == nil { so.IsFollowing = inFollowing } } if query.Get("online") != "" { inFollowing, err := strconv.ParseBool(query.Get("online")) if err == nil { so.IsOnline = inFollowing } } return so }
🌐
TutorialsPoint
tutorialspoint.com › article › golang-program-to-convert-string-type-variables-into-boolean
Golang Program to convert string type variables into Boolean
November 14, 2022 - ParseBool() function is used to convert strings to integer type values. This function accepts one arguments which is the string that we wish to convert.
🌐
GitHub
github.com › colinhacks › zod › issues › 2985
Parse a boolean value represented by string logically · Issue #2985 · colinhacks/zod
November 23, 2023 - ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
Author   jlandowner
🌐
Eternaldev
eternaldev.com › blog › convert-string-to-bool-in-golang
Convert string to bool in Golang - Eternal Dev | Learn Web development
October 29, 2022 - Converting string to bool can be done using the strconv.ParseBool method. It tries to return a boolean value from a string. It accepts the strings in the following format 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False
🌐
Go
go.dev › play › p › E6nZ6B8P6V
Go Playground - The Go Programming Language
Any requests for content removal should be directed to security@golang.org.
🌐
GitHub
github.com › sidhant92 › bool-parser-go
GitHub - sidhant92/bool-parser-go: A Simple to Use, Complex Boolean & Arithmetic Expression Parser Written For Go
A Simple to Use, Complex Boolean & Arithmetic Expression Parser Written For Go - sidhant92/bool-parser-go
Author   sidhant92
🌐
GitHub
github.com › golang › go › issues › 29306
strconv: ParseBool errors are verbose · Issue #29306 · golang/go
December 17, 2018 - Failure to parse a boolean flag results in this error: https://play.golang.org/p/cBBLtiFyWhY: invalid boolean value "garbage" for -b: strconv.ParseBool: parsing "garbage": inval...
Author   alandonovan
🌐
Melvin George
melvingeorge.me › blog › convert-boolean-string-type-value-to-bool-type-value-go-golang
How to convert a boolean string type value to a bool type value in Go or Golang? | MELVIN GEORGE
August 22, 2022 - To convert a boolean-based string type value to a bool type value, you can use the ParseBool() method from the strconv standard package in Go or Golang.