json

package
v3.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 2 Imported by: 0

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

View Source
var (
	Marshal       = api.Marshal
	Unmarshal     = api.Unmarshal
	MarshalIndent = api.MarshalIndent
	NewDecoder    = api.NewDecoder
	NewEncoder    = api.NewEncoder
)

Exported functions from the sonic.API.

Functions

func SetConfig added in v3.4.6

func SetConfig(config *sonic.Config)

SetConfig sets the configuration for the JSON package.

Types

type Decoder

type Decoder = sonic.Decoder

Decoder is a JSON decoder.

type Encoder

type Encoder = sonic.Encoder

Encoder is a JSON encoder.

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

type Marshaler interface {
	MarshalJSON() ([]byte, error)
}

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

func (m Message) MarshalJSON() ([]byte, error)

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

func (m *Message) UnmarshalJSON(data []byte) error

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

type Unmarshaler interface {
	UnmarshalJSON([]byte) error
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL