Skip to content

Instantly share code, notes, and snippets.

@mecitsemerci
mecitsemerci / jsonconvert.go
Last active August 15, 2023 10:32
JSON serialize and deserialize using go generics
package jsonconvert
import "encoding/json"
func Deserialize[T any](str string) (T, error) {
var d T
err := json.Unmarshal([]byte(str), &d)
if err != nil {
return d, err
}
@mecitsemerci
mecitsemerci / json_time.go
Last active December 23, 2022 04:39
Golang json (un)marshal custom date formats
package customTypes
import (
"errors"
"fmt"
"strings"
"time"
)
type JSONTime time.Time