Documentation
¶
Overview ¶
Package json provides fast JSON encoding and decoding functionality.
On supported platforms; Linux, Darwin, or Windows on amd64, or on arm64 with Go >= 1.20 and <= 1.24, the package uses the high-performance sonic library. On any other systems, it gracefully falls back to using the [go-json] implementation.
This package acts as a wrapper around the underlying JSON APIs, offering standard operations such as marshaling, unmarshaling, and working with JSON encoders/decoders. It maintains compatibility with the standard encoding/json interfaces while delivering improved performance when possible.
Additionally, it defines the customary Marshaler and Unmarshaler interfaces to facilitate custom JSON encoding and decoding implementations.
TODO(dwisiswant0): This package should be moved to the github.com/projectdiscovery/utils/json, but let see how it goes first.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( Marshal = api.Marshal Unmarshal = api.Unmarshal MarshalIndent = api.MarshalIndent NewDecoder = api.NewDecoder NewEncoder = api.NewEncoder )
Exported functions from the sonic.API.
Functions ¶
Types ¶
type JSONCodec ¶
type JSONCodec interface {
Marshaler
Unmarshaler
}
JSONCodec is the interface implemented by types that can marshal and unmarshal themselves into valid JSON.
type Marshaler ¶
Marshaler is the interface implemented by types that can marshal themselves into valid JSON.
type Message ¶
type Message []byte
Message is a raw encoded JSON value. It implements Marshaler and Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding.
Copied from: https://cs.opensource.google/go/go/+/refs/tags/go1.23.6:src/encoding/json/stream.go;l=256-276
func (Message) MarshalJSON ¶
MarshalJSON returns m as the JSON encoding of m.
Copied from: https://cs.opensource.google/go/go/+/refs/tags/go1.23.6:src/encoding/json/stream.go;l=256-276
func (*Message) UnmarshalJSON ¶
UnmarshalJSON sets *m to a copy of data.
Copied from: https://cs.opensource.google/go/go/+/refs/tags/go1.23.6:src/encoding/json/stream.go;l=256-276
type Unmarshaler ¶
Unmarshaler is the interface implemented by types that can unmarshal a JSON description of themselves. The input can be assumed to be a valid encoding of a JSON value. UnmarshalJSON must copy the JSON data if it wishes to retain the data after returning.
By convention, to approximate the behavior of Unmarshal itself, Unmarshalers implement UnmarshalJSON([]byte("null")) as a no-op.