21 lines
342 B
Go
21 lines
342 B
Go
|
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
|
||
|
}
|