Documentation
¶
Index ¶
- Constants
- Variables
- func Marshal(v any) ([]byte, error)
- func MarshalIndent(v any, prefix, indent string) ([]byte, error)
- func MarshalToString(v any) (string, error)
- func Reset()
- func Unmarshal(data []byte, v any) error
- func Valid(data []byte) bool
- type Decoder
- type Encoder
- type JSON
- type Marshaller
- type Unmarshaller
- type Validator
Constants ¶
const ( // StdLib is the JSON implementation of package/json. StdLib = "std" // SonnetLib is the JSON implementation of github.com/rudderlabs/sonnet. SonnetLib = "sonnet" // JsoniterLib is the JSON implementation of github.com/json-iterator/go. JsoniterLib = "jsoniter" // DefaultLib is the default JSON implementation. DefaultLib = SonnetLib )
Variables ¶
var Default = New(config.Default)
Functions ¶
func MarshalIndent ¶
MarshalIndent returns the JSON encoding of v with indentation. Uses the default JSON implementation.
func MarshalToString ¶
MarshalToString returns the JSON encoding of v as a string. Uses the default JSON implementation.
func Reset ¶
func Reset()
Reset resets the default JSON implementation based on the default configuration.
Types ¶
type Decoder ¶
type Decoder interface { Buffered() io.Reader Decode(v any) error DisallowUnknownFields() More() bool UseNumber() }
Decoder is the interface that wraps the basic JSON decoder operations.
func NewDecoder ¶
NewDecoder returns a new json decoder that reads from r. Uses the default JSON implementation.
type Encoder ¶
type Encoder interface { Encode(v any) error SetEscapeHTML(on bool) SetIndent(prefix, indent string) }
Encoder is the interface that wraps the basic JSON encoder operations.
func NewEncoder ¶
NewEncoder returns a new json encoder that writes to w. Uses the default JSON implementation.
type JSON ¶
type JSON interface { Marshaller Unmarshaller Validator }
JSON is the interface that wraps the basic JSON operations.
func NewWithLibrary ¶
NewWithLibrary returns a new JSON implementation based on the library.
type Marshaller ¶
type Marshaller interface { // Marshal returns the JSON encoding of v. Marshal(v any) ([]byte, error) // MarshalToString returns the JSON encoding of v as a string. MarshalToString(v any) (string, error) // MarshalIndent returns the JSON encoding of v with indentation. MarshalIndent(v any, prefix, indent string) ([]byte, error) // NewEncoder returns a new json encoder that writes to an io.Writer NewEncoder(w io.Writer) Encoder }