package ersteller import "encoding/json" type JSONB map[string]interface{} func StructToMap(data interface{}) (JSONB, error) { var result JSONB // Marshal struct to JSON bytes jsonBytes, err := json.Marshal(data) if err != nil { return nil, err } // Unmarshal JSON bytes to map err = json.Unmarshal(jsonBytes, &result) if err != nil { return nil, err } return result, nil } func MapToStruct(data JSONB, result any) error { // Marshal map to JSON bytes jsonBytes, err := json.Marshal(data) if err != nil { return err } // Unmarshal JSON bytes to struct err = json.Unmarshal(jsonBytes, result) if err != nil { return err } return nil }