standard/pkg/json/json.go
2026-03-28 19:31:44 +08:00

26 lines
436 B
Go

package json
import (
"encoding/json"
"os"
)
var (
Marshal = json.Marshal
Unmarshal = json.Unmarshal
MarshalIndent = json.MarshalIndent
NewDecoder = json.NewDecoder
NewEncoder = json.NewEncoder
)
// Parse Parses the given JSON file
func Parse(name string, obj interface{}) error {
f, err := os.Open(name)
if err != nil {
return err
}
defer func() { _ = f.Close() }()
return NewDecoder(f).Decode(obj)
}