# cast

> Easy and safe casting from one type to another in Go

Source: https://talira.ai/catalog/cast-8mxn794h
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [libraries / general purpose](https://talira.ai/categories/libraries/general-purpose), [languages / go](https://talira.ai/categories/languages/go)
- Licence: MIT[^2]
- Pricing: Free and open source[^1]
- Free tier: yes[^1]
- Backed by: [Steve Francia](https://talira.ai/orgs/spf13.md)

cast is a Go library for converting between types in a consistent way: a number to a string, an interface{} to a bool, a string such as "8" to an int. It converts only when the conversion is obvious and never guesses what you meant. Each To... function returns the zero value when it can't convert, and a matching To...E function also returns an error, so you can tell a failed conversion from a real zero. It suits dynamic data such as values decoded from YAML, TOML or JSON, and was written for [Hugo](https://talira.ai/catalog/hugo-5t27gqmf.md) by Steve Francia.

## Links

- GitHub: https://github.com/spf13/cast
- Docs: https://pkg.go.dev/github.com/spf13/cast

## Problems it solves

- turn an interface{} value from decoded YAML or JSON into a string or int in Go
- convert config values of unknown type in Go without writing type switches everywhere
- tell a failed conversion apart from a real zero value

## Features

- To... functions that always return the type asked for (ToString, ToInt and more)
- To...E variants that return an error alongside the result
- converts only when the conversion is obvious

## Trust

Overall: 0.46 out of 1.
Signals: maintenance 0.48, adoption 0.72, momentum 0.43, community 0.63, backing 0.30, extensibility 0.00.

- last commit 2 months ago
- 5 commits in the last 90 days
- latest release v1.10.0 14 months ago
- 4.0k GitHub stars
- 37 contributors
- backed by Steve Francia

## Alternatives

- [swag](https://talira.ai/catalog/swag-dyds8yf8.md): Helper modules for Go: type conversion, JSON and YAML utilities, name mangling

## Sources

[^1]: https://github.com/spf13/cast/blob/master/README.md (checked 28 Nov 2026)
[^2]: https://github.com/spf13/cast/blob/master/LICENSE (checked 28 Nov 2026)
