json

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package json provides high-performance JSON serialization with object pooling

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBuffer

func GetBuffer() *bytes.Buffer

GetBuffer gets a pooled bytes.Buffer

func GetDecoder

func GetDecoder(r io.Reader) *gojson.Decoder

GetDecoder gets a pooled JSON decoder

func GetEncoder

func GetEncoder(w io.Writer) *gojson.Encoder

GetEncoder gets a pooled JSON encoder

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal is a high-performance drop-in replacement for json.Marshal

func MarshalArray

func MarshalArray(values []interface{}) ([]byte, error)

MarshalArray efficiently marshals a slice as a JSON array

func MarshalIndent

func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

MarshalIndent is a high-performance replacement for json.MarshalIndent

func MarshalMultiple

func MarshalMultiple(values []interface{}, separator []byte) ([]byte, error)

MarshalMultiple efficiently marshals multiple objects to a single buffer

func MarshalRecords

func MarshalRecords(records []*pool.Record, format string) ([]byte, error)

MarshalRecords efficiently marshals a slice of records

func MarshalRecordsArray

func MarshalRecordsArray(records []*pool.Record) ([]byte, error)

MarshalRecordsArray marshals records as a JSON array

func MarshalRecordsLines

func MarshalRecordsLines(records []*pool.Record) ([]byte, error)

MarshalRecordsLines marshals records as line-delimited JSON

func MarshalToBuffer

func MarshalToBuffer(v interface{}) (*bytes.Buffer, error)

MarshalToBuffer marshals v to a pooled buffer

func MarshalToWriter

func MarshalToWriter(w io.Writer, v interface{}) error

MarshalToWriter marshals v directly to a writer using pooled encoder

func PutBuffer

func PutBuffer(buf *bytes.Buffer)

PutBuffer returns a buffer to the pool

func PutDecoder

func PutDecoder(dec *gojson.Decoder)

PutDecoder returns a decoder to the pool

func PutEncoder

func PutEncoder(enc *gojson.Encoder)

PutEncoder returns an encoder to the pool

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal is a high-performance drop-in replacement for json.Unmarshal

Types

type JSONPool

type JSONPool struct {
	// contains filtered or unexported fields
}

JSONPool manages pooled JSON encoders and decoders

type OptimizedJSONWriter

type OptimizedJSONWriter struct {
	// contains filtered or unexported fields
}

OptimizedJSONWriter provides high-performance JSON writing with minimal allocations

func NewOptimizedJSONWriter

func NewOptimizedJSONWriter(initialSize int) *OptimizedJSONWriter

NewOptimizedJSONWriter creates a new optimized JSON writer

func (*OptimizedJSONWriter) Bytes

func (w *OptimizedJSONWriter) Bytes() []byte

Bytes returns the accumulated JSON bytes

func (*OptimizedJSONWriter) Reset

func (w *OptimizedJSONWriter) Reset()

Reset resets the writer for reuse

func (*OptimizedJSONWriter) WriteField

func (w *OptimizedJSONWriter) WriteField(key string, value interface{}) error

WriteField efficiently writes a JSON field

type StreamingEncoder

type StreamingEncoder struct {
	// contains filtered or unexported fields
}

StreamingEncoder provides efficient streaming JSON encoding

func NewStreamingEncoder

func NewStreamingEncoder(w io.Writer, isArray bool) *StreamingEncoder

NewStreamingEncoder creates a new streaming encoder

func (*StreamingEncoder) Close

func (se *StreamingEncoder) Close() error

Close finalizes the encoding

func (*StreamingEncoder) Encode

func (se *StreamingEncoder) Encode(v interface{}) error

Encode encodes a single value

func (*StreamingEncoder) SetPretty

func (se *StreamingEncoder) SetPretty(pretty bool, indent string)

SetPretty enables pretty printing

Jump to

Keyboard shortcuts

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