jsonutil

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: MPL-2.0 Imports: 8 Imported by: 92

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(data []byte, out interface{}) error

DecodeJSON tries to decompress the given data. The call to decompress, fails if the content was not compressed in the first place, which is identified by a canary byte before the compressed data. If the data is not compressed, it is JSON decoded directly. Otherwise the decompressed data will be JSON decoded.

func DecodeJSONFromReader

func DecodeJSONFromReader(r io.Reader, out interface{}) error

DecodeJSONFromReader Decodes/Unmarshals the given io.Reader pointing to a JSON, into a desired object

func EncodeJSON

func EncodeJSON(in interface{}) ([]byte, error)

EncodeJSON encodes/marshals the given object into JSON

func EncodeJSONAndCompress

func EncodeJSONAndCompress(in interface{}, config *compressutil.CompressionConfig) ([]byte, error)

EncodeJSONAndCompress encodes the given input into JSON and compresses the encoded value (using Gzip format BestCompression level, by default). A canary byte is placed at the beginning of the returned bytes for the logic in decompression method to identify compressed input.

func VerifyMaxDepthStreaming added in v0.19.0

func VerifyMaxDepthStreaming(jsonReader io.Reader, limits JSONLimits) (int, error)

VerifyMaxDepthStreaming scans the JSON stream to determine its maximum nesting depth and enforce various limits. It first checks if the stream is likely JSON before proceeding.

Types

type JSONLimits added in v0.19.0

type JSONLimits struct {
	MaxDepth             int
	MaxStringValueLength int
	MaxObjectEntryCount  int
	MaxArrayElementCount int
}

JSONLimits defines the configurable limits for JSON validation.

Jump to

Keyboard shortcuts

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