anyjson

package
v0.0.0-...-6b347e5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 17 Imported by: 7

Documentation

Index

Constants

View Source
const (
	PatchOpReplace = "replace"
	PatchOpDelete  = "delete"
)

Variables

View Source
var PatchKey = "$patch"

Functions

func As

func As[T Valuer](valuer T, target any) error

func Equal

func Equal(a Valuer, b Valuer) bool

func Merge

func Merge[T Valuer](base T, patch T, opts ...MergeOption) T

func Sorted

func Sorted[T Valuer](v T) T

func ToString

func ToString(valuer Valuer) string

Types

type Array

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

func (*Array) Append

func (v *Array) Append(item Valuer)

func (*Array) Index

func (v *Array) Index(i int) (Valuer, bool)

func (*Array) IndexedValues

func (v *Array) IndexedValues() iter.Seq2[int, Valuer]

func (*Array) Len

func (v *Array) Len() int

func (*Array) MarshalJSON

func (v *Array) MarshalJSON() ([]byte, error)

func (*Array) String

func (v *Array) String() string

func (*Array) UnmarshalJSON

func (v *Array) UnmarshalJSON(b []byte) error

func (*Array) UnmarshalJSONFrom

func (v *Array) UnmarshalJSONFrom(d *jsontext.Decoder) error

func (*Array) Value

func (v *Array) Value() any

func (*Array) Values

func (v *Array) Values() iter.Seq[Valuer]

type ArrayMergeKeyOption

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

func WithArrayMergeKey

func WithArrayMergeKey(key string) *ArrayMergeKeyOption

func (*ArrayMergeKeyOption) ApplyToDiff

func (o *ArrayMergeKeyOption) ApplyToDiff(d *differ)

func (*ArrayMergeKeyOption) ApplyToMerge

func (o *ArrayMergeKeyOption) ApplyToMerge(m *merger)

type Boolean

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

func BooleanOf

func BooleanOf(b bool) *Boolean

func (*Boolean) MarshalJSON

func (v *Boolean) MarshalJSON() ([]byte, error)

func (*Boolean) String

func (v *Boolean) String() string

func (*Boolean) Value

func (v *Boolean) Value() any

type DiffOption

type DiffOption interface {
	ApplyToDiff(d *differ)
}

type EmptyObjectAsNullOption

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

func WithEmptyObjectAsNull

func WithEmptyObjectAsNull() *EmptyObjectAsNullOption

func (*EmptyObjectAsNullOption) ApplyToDiff

func (o *EmptyObjectAsNullOption) ApplyToDiff(d *differ)

func (*EmptyObjectAsNullOption) ApplyToMerge

func (o *EmptyObjectAsNullOption) ApplyToMerge(m *merger)

type List

type List = []any

type MergeOption

type MergeOption interface {
	ApplyToMerge(m *merger)
}

type Null

type Null struct{}

func (*Null) MarshalJSON

func (v *Null) MarshalJSON() ([]byte, error)

func (*Null) String

func (v *Null) String() string

func (*Null) UnmarshalJSON

func (v *Null) UnmarshalJSON(bytes []byte) error

func (*Null) Value

func (*Null) Value() any

type NullOp

type NullOp int
const (
	NullIgnore NullOp = iota
	NullAsRemover
)

type NullOption

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

func WithNullOp

func WithNullOp(op NullOp) *NullOption

func (*NullOption) ApplyToMerge

func (n *NullOption) ApplyToMerge(m *merger)

type Number

type Number[T number] struct {
	// contains filtered or unexported fields
}

func NumberOf

func NumberOf[T number](n T) *Number[T]

func (*Number[T]) MarshalJSON

func (v *Number[T]) MarshalJSON() ([]byte, error)

func (*Number[T]) String

func (v *Number[T]) String() string

func (*Number[T]) Value

func (v *Number[T]) Value() any

type Obj

type Obj = map[string]any

type Object

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

func (*Object) Delete

func (v *Object) Delete(key string) (didDelete bool)

func (*Object) Get

func (v *Object) Get(key string) (Valuer, bool)

func (*Object) KeyValues

func (v *Object) KeyValues() iter.Seq2[string, Valuer]

func (*Object) Len

func (v *Object) Len() int

func (Object) MarshalJSON

func (v Object) MarshalJSON() ([]byte, error)

func (*Object) Set

func (v *Object) Set(key string, value Valuer) bool

func (*Object) String

func (v *Object) String() string

func (*Object) UnmarshalJSON

func (v *Object) UnmarshalJSON(b []byte) error

func (*Object) UnmarshalJSONFrom

func (v *Object) UnmarshalJSONFrom(d *jsontext.Decoder) error

func (*Object) Value

func (v *Object) Value() any

type PatchOp

type PatchOp string

func IsPatchObject

func IsPatchObject(obj *Object) (PatchOp, bool)

type String

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

func StringOf

func StringOf(v string) *String

func (*String) MarshalJSON

func (v *String) MarshalJSON() ([]byte, error)

func (*String) String

func (v *String) String() string

func (*String) Value

func (v *String) Value() any

type Valuer

type Valuer interface {
	json.Marshaler

	fmt.Stringer

	Value() any
}

func Diff

func Diff[T any](template *T, live *T, opts ...DiffOption) (Valuer, error)

func FromJSONTextDecoder

func FromJSONTextDecoder(decoder *jsontext.Decoder) (Valuer, error)

func FromValue

func FromValue(value any) (Valuer, error)

func MustFromValue

func MustFromValue(value any) Valuer

func Transform

func Transform(ctx context.Context, v Valuer, transform func(v Valuer, keyPath ...any) Valuer) Valuer

Jump to

Keyboard shortcuts

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