https://github.com/otterize/nilable
nilable is a tiny Go generics library for making non-nilable values nilable
https://github.com/otterize/nilable
Last synced: 6 months ago
JSON representation
nilable is a tiny Go generics library for making non-nilable values nilable
- Host: GitHub
- URL: https://github.com/otterize/nilable
- Owner: otterize
- License: apache-2.0
- Created: 2023-02-06T19:38:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-22T13:52:31.000Z (over 1 year ago)
- Last Synced: 2025-10-22T16:02:38.490Z (9 months ago)
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nilable
nilable is a tiny Go generics library for making non-`nil`able values nilable, and supports JSON serialization.
You too can stop using pointers when you don't need them!
## From value to JSON
```go
nilableString := nilable.From("hello world")
println(nilableString.Set) // true
println(nilableString.Item) // "hello world"
data, _ := json.Marshal(nilableString)
println(string(data)) // `"hello world"`
```
## From null JSON to value
```go
var nilableString Nilable[string]
json.Unmarshal([]byte("null"), &nilJson)
println(nilJson.Set) // false
```