-
Notifications
You must be signed in to change notification settings - Fork 180
/
json.go
32 lines (24 loc) · 866 Bytes
/
json.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package jsonx
import (
"encoding/json"
"io"
jsoniter "github.com/json-iterator/go"
)
type Marshaler json.Marshaler
type Unmarshaler json.Unmarshaler
func Marshal(v interface{}) ([]byte, error) {
return jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(v)
}
func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
// MarshalIndent compatible with standard library doesn't indent properly so using directly the old json lib
return json.MarshalIndent(v, prefix, indent)
}
func Unmarshal(data []byte, v interface{}) error {
return jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, v)
}
func NewEncoder(w io.Writer) *jsoniter.Encoder {
return jsoniter.ConfigCompatibleWithStandardLibrary.NewEncoder(w)
}
func NewDecoder(r io.Reader) *jsoniter.Decoder {
return jsoniter.ConfigCompatibleWithStandardLibrary.NewDecoder(r)
}