jsonutil

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmptyObject = "{}"
)

Variables

This section is empty.

Functions

func Base64JSONDecode

func Base64JSONDecode[T any](s string) (T, error)

func Base64JSONEncode

func Base64JSONEncode[T any](t T) string

func Canonicalize added in v0.2.13

func Canonicalize(raw []byte) ([]byte, error)

func CanonicalizeObject added in v0.2.13

func CanonicalizeObject(raw []byte, maximum int) ([]byte, error)

func CloneJSON added in v0.2.17

func CloneJSON[T any](input T) (T, error)

CloneJSON returns a copy of input produced by a JSON marshal/unmarshal round trip. It intentionally does not use DecodeJSONRaw, because clone semantics should match json.Unmarshal rather than reject unknown fields.

func CloneJSONInValue added in v0.2.17

func CloneJSONInValue[T any](in T) T

func DecodeCanonicalObject added in v0.2.17

func DecodeCanonicalObject[T any](raw []byte, maximumBytes int) (T, error)

DecodeCanonicalObject validates raw as one JSON object, canonicalizes it, and strictly decodes it into T. It rejects duplicate keys, unknown struct fields, and trailing JSON values.

As with CanonicalizeObject, an empty raw value is treated as {}.

func DecodeJSONRaw

func DecodeJSONRaw[T any](raw json.RawMessage) (T, error)

DecodeJSONRaw decodes a json.RawMessage into a typed value T, disallowing unknown fields and rejecting trailing data. If raw is empty, or only whitespace, it returns the zero value of T.

func EncodeToJSONRaw

func EncodeToJSONRaw(value any) (json.RawMessage, error)

EncodeToJSONRaw encodes any value to json.RawMessage. No typed method here as value being of a type doesnt really affect its functionality.

func Equal added in v0.2.13

func Equal(left, right []byte) bool

func LogJSON added in v0.2.17

func LogJSON(level slog.Level, v any)

func MarshalCanonicalObject added in v0.2.17

func MarshalCanonicalObject(value any, maximumBytes int) (json.RawMessage, error)

MarshalCanonicalObject marshals value as a canonical JSON object. The maximum applies to the marshaled JSON before canonicalization.

Types

type JSONRawString added in v0.2.17

type JSONRawString string

func (JSONRawString) MarshalJSON added in v0.2.20

func (value JSONRawString) MarshalJSON() ([]byte, error)

func (*JSONRawString) UnmarshalJSON added in v0.2.20

func (value *JSONRawString) UnmarshalJSON(raw []byte) error

type JSONSchema added in v0.2.17

type JSONSchema = json.RawMessage

Jump to

Keyboard shortcuts

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