jsonstructure

package
v0.0.0-...-e7c744b Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const WithZeroStructsAsEmpty zeroStructIsEmptyOption = true

WithZeroStructsAsEmpty is an encoding option that makes the encoder treat struct values equal to their default (zero) value as empty.

Variables

This section is empty.

Functions

func Copy

func Copy(v interface{}) (interface{}, error)

Copy returns a deep copy of a JSON structure value.

A JSON structure value is one of: - nil - a bool - a number (float64) - a string - a []interface{} - a map[string]interface{} where the last two can only contain JSON structure values.

func DefaultMergeOptions

func DefaultMergeOptions() any.MergeOptions

DefaultMergeOptions returns the default merge options for JSON structure values

func Encode

func Encode(v interface{}, options ...EncodeOption) (interface{}, error)

Encode returns a transformation of v that is equivalent with JSON encoding and decoding v.

Types

type AppendArrayMergeStrategy

type AppendArrayMergeStrategy struct {
	// SecondFirst makes the strategy copy elements from the second array to the result before elements from the first array if true.
	SecondFirst bool
}

AppendArrayMergeStrategy is a merge strategy for JSON arrays, concatenating the two arrays.

func (AppendArrayMergeStrategy) Merge

func (ms AppendArrayMergeStrategy) Merge(_ any.MergeContext, fst, snd any.Value) (any.Value, error)

Merge returns the combination of two JSON arrays by concatenating them.

type Array

type Array = []Value

Array represents a JSON array.

func CopyArray

func CopyArray(arr Array) (Array, error)

CopyArray returns a deep copy of a JSON array. Elements of the array must be valid JSON structure values.

type Boolean

type Boolean = bool

Boolean represents a JSON boolean.

type EncodeOption

type EncodeOption interface {
	// contains filtered or unexported methods
}

EncodeOption represents an encoding option.

type EncodeOptions

type EncodeOptions []EncodeOption

EncodeOptions is a list of encoding options.

type Number

type Number = float64

Number represents a JSON number.

type Object

type Object = map[string]Value

Object represents a JSON object.

func CopyObject

func CopyObject(obj Object) (Object, error)

CopyObject returns a deep copy of a JSON object. Members of the object must be valid JSON structure values

type PairwiseArrayMergeStrategy

type PairwiseArrayMergeStrategy struct {
	// InnerJoin makes the strategy merge only elements at common indices of the two arrays.
	InnerJoin bool
}

PairwiseArrayMergeStrategy is a merge strategy for JSON arrays, merging array elements with matching indices. If InnerJoin is true, the resulting array will contain only the result of merging elements of the arrays with matching indices; otherwise, the rest of the elements from the longer array are copied to the result array beyond the common, merged part.

func (PairwiseArrayMergeStrategy) Merge

func (ms PairwiseArrayMergeStrategy) Merge(ctx any.MergeContext, fst, snd any.Value) (any.Value, error)

Merge returns the combination of two JSON arrays using a pairwise merge strategy.

type PairwiseObjectMergeStrategy

type PairwiseObjectMergeStrategy struct {
	InnerJoin bool
}

PairwiseObjectMergeStrategy is a merge strategy for JSON objects, merging object members with matching keys. If InnerJoin is true, the result will be the union of the intersection of the two objects, pairwise merging members with matching keys; otherwise, the result will be the union of the two objects, pairwise merging members with matching keys.

func (PairwiseObjectMergeStrategy) Merge

func (ms PairwiseObjectMergeStrategy) Merge(ctx any.MergeContext, fst, snd any.Value) (any.Value, error)

Merge returns the combination of two JSON objects using a pairwise merge strategy.

type String

type String = string

String represents a JSON string.

type Value

type Value = interface{}

Value represents any JSON value

Jump to

Keyboard shortcuts

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