Skip to content

portalnesia/go-nullable

Repository files navigation

Go Reference Go

Nullable

Nullable Data Type for json and database

Install

go get go.portalnesia.com/nullable

Example

package main

import (
	"encoding/json"
	"fmt"
	"go.portalnesia.com/nullable"
)

type JsonType struct {
	String nullable.String `json:"string"`
}

func main() {
	dataJson := []byte(`{"string":null}`)

    var data JsonType
    if err := json.Unmarshal(dataJson,&data); err != nil {
        panic(err)
    }
	
    fmt.Println(data.String)
}

Go References

pkg.go.dev/go.portalnesia.com/nullable