yoake/internal/servetpl/funcmap/json.go

21 lines
342 B
Go
Raw Normal View History

2022-11-07 04:45:02 -06:00
package funcmap
import "encoding/json"
func ParseJSON(s string) (interface{}, error) {
var v interface{}
if err := json.Unmarshal([]byte(s), &v); err != nil {
return nil, err
}
return v, nil
}
func MarshalJSON(v interface{}) (string, error) {
b, err := json.Marshal(v)
if err != nil {
return "", err
}
return string(b), nil
}