Documentation ¶
Index ¶
- Constants
- func Copy(v interface{}) (interface{}, error)
- func DefaultMergeOptions() any.MergeOptions
- func Encode(v interface{}, options ...EncodeOption) (interface{}, error)
- type AppendArrayMergeStrategy
- type Array
- type Boolean
- type EncodeOption
- type EncodeOptions
- type Number
- type Object
- type PairwiseArrayMergeStrategy
- type PairwiseObjectMergeStrategy
- type String
- type Value
Constants ¶
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 EncodeOption ¶
type EncodeOption interface {
// contains filtered or unexported methods
}
EncodeOption represents an encoding option.
type Object ¶
Object represents a JSON object.
func CopyObject ¶
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.