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
🌐
ZetCode
zetcode.com › golang › strconv-parsebool
Using strconv.ParseBool in Go
April 20, 2025 - Learn how to parse boolean values from strings using strconv.ParseBool in Go. Includes practical examples and error handling.
🌐
Educative
educative.io › answers › how-to-use-the-strconvparsebool-function-in-golang
How to use the strconv.ParseBool() function in Golang
Lines 3 to 6: We import the necessary packages in Golang project. Lines 11 to 21: We define the main() function and the strconv.ParseBool() function, which checks whether the string passed is a boolean value or not.
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
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
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
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
🌐
Dot Net Perls
dotnetperls.com › convert-string-bool-go
Go - Convert String to Bool: strconv.ParseBool - Dot Net Perls
May 24, 2021 - For converting types, strconv is essential in Go. We use ParseBool and FormatBool to convert strings to bools (parsing them) and bools to strings. Dot Net Perls is a collection of code tutorials.
🌐
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.
🌐
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 - Whether you’re reading configuration files, processing user input, or handling API responses, you’ll frequently need to convert string representations into their appropriate data types. Go’s strconv package provides three essential functions for this purpose: ParseBool, ParseInt, and ParseUint.
🌐
IncludeHelp
includehelp.com › golang › strconv-parsebool-function-with-examples.aspx
Golang strconv.ParseBool() Function with Examples
September 7, 2021 - // Golang program to demonstrate the // example of strconv.ParseBool() Function package main import ( "fmt" "strconv" ) func main() { v := "true" s, err := strconv.ParseBool(v) if err == nil { fmt.Println("Parsing done...") fmt.Printf("%T, %v\n", s, s) } else { fmt.Println("Parsing failed...") fmt.Printf("Error:%v\n", err) } fmt.Println() v = "false" s, err = strconv.ParseBool(v) if err == nil { fmt.Println("Parsing done...") fmt.Printf("%T, %v\n", s, s) } else { fmt.Println("Parsing failed...") fmt.Printf("Error:%v\n", err) } fmt.Println() v = "No" s, err = strconv.ParseBool(v) if err == nil { fmt.Println("Parsing done...") fmt.Printf("%T, %v\n", s, s) } else { fmt.Println("Parsing failed...") fmt.Printf("Error:%v\n", err) } fmt.Println() }
🌐
HotExamples
golang.hotexamples.com › examples › strconv › - › ParseBool › golang-parsebool-function-examples.html
Golang ParseBool Examples, strconv.ParseBool Golang Examples - HotExamples
func getValidationRules(m reflect.StructField) (map[string]interface{}, error) { tags := make(map[string]interface{}) if tagType := m.Tag.Get(TypeTag); tagType != "" { switch tagType { case EmailTag: tags[EmailTag] = true case PhoneIndiaTag: tags[PhoneIndiaTag] = true } } if tagVal := m.Tag.Get(EmailTag); tagVal != "" { boolVal, err := strconv.ParseBool(tagVal) if err != nil { panic(err) } if boolVal { tags[EmailTag] = boolVal } } if tagVal := m.Tag.Get(RequiredTag); tagVal != "" { boolVal, err := strconv.ParseBool(tagVal) if err != nil { panic(err) } if boolVal { tags[RequiredTag] = boolVal }
Find elsewhere
🌐
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 - Then we are calling ParseBool() function from the "strconv" package of go language, and pass the string to the function. Now we have printed the type of variable, to check if the data type is changed from string to boolean or not.
🌐
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.
🌐
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 - Learn how to use the `ParseBool()` method from the `strconv` package to convert a string type value to a bool type value in Go or Golang
🌐
Reintech
reintech.io › term › using-strconv-parsebool-function-go
Using strconv.ParseBool() Function in Go | Reintech media
Learn how to use strconv.ParseBool() function in Go for converting strings to boolean values.
🌐
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 › colinhacks › zod › issues › 2985
Parse a boolean value represented by string logically · Issue #2985 · colinhacks/zod
November 23, 2023 - The transforming specification in Go standard library's strconv.ParseBool() is good for it.
Author   jlandowner
🌐
Cloudhadoop
cloudhadoop.com › home
Multiple ways to Convert string to/from boolean in Golang code examples
December 31, 2023 - ParseBool() function takes boolean value in the form String(“true”) and returns a boolean value.
🌐
GeeksforGeeks
geeksforgeeks.org › converting-a-string-variable-into-boolean-integer-or-float-type-in-golang
Converting a string variable into Boolean, Integer or Float type in Golang | GeeksforGeeks
May 10, 2020 - Package strconv is imported to perform conversions to and from string. ParseBool is used to convert string to boolean value. It accepts 1, t, T, TRUE, true, True as true and 0, f, F, FALSE, false, False as false.