26 lines
436 B
Go
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)
|
|
}
|