Documentation
¶
Overview ¶
Package json implements JSON codec for JSON Patch operations. Provides encoding and decoding functionality for JSON Patch operations with full RFC 6902 support.
Package json implements JSON Patch decoder functionality.
Package json implements JSON codec for JSON Patch operations.
Package json implements JSON Patch encoder functionality.
Package json implements JSON codec for JSON Patch operations. Provides encoding and decoding functionality for JSON Patch operations with full RFC 6902 support.
Index ¶
- Variables
- func Decode(operations []map[string]interface{}, options internal.JSONPatchOptions) ([]internal.Op, error)
- func DecodeJSON(data []byte, options internal.JSONPatchOptions) ([]internal.Op, error)
- func DecodeOperations(operations []internal.Operation, options internal.JSONPatchOptions) ([]internal.Op, error)
- func Encode(ops []internal.Op) ([]internal.Operation, error)
- func EncodeJSON(ops []internal.Op) ([]byte, error)
- func OperationToOp(operation map[string]interface{}, options internal.JSONPatchOptions) (internal.Op, error)
- func OperationToPredicateOp(operation map[string]interface{}, options internal.JSONPatchOptions) (internal.Op, error)
- type CompactOperation
- type Decoder
- type Encoder
- type Operation
- type Options
- type PatchOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidPointer = errors.New("invalid pointer") ErrAddOpMissingValue = errors.New("add operation missing 'value' field") ErrReplaceOpMissingValue = errors.New("replace operation missing 'value' field") ErrNotOpRequiresOperand = errors.New("not operation requires at least one operand") ErrMissingValueField = errors.New("missing value field") ErrEmptyTypeList = errors.New("empty type list") ErrInvalidType = errors.New("invalid type") ErrNotOpRequiresValidOperand = errors.New("not operation requires a valid predicate operand") )
Decode operation errors - define clearly and concisely
var ( // ErrOpMissingOpField indicates operation is missing 'op' field ErrOpMissingOpField = errors.New("operation missing 'op' field") // ErrOpMissingPathField indicates operation is missing 'path' field ErrOpMissingPathField = errors.New("operation missing 'path' field") // ErrMoveOpMissingFrom indicates move operation is missing 'from' field ErrMoveOpMissingFrom = errors.New("move operation missing 'from' field") // ErrCopyOpMissingFrom indicates copy operation is missing 'from' field ErrCopyOpMissingFrom = errors.New("copy operation missing 'from' field") // ErrIncOpMissingInc indicates inc operation is missing 'inc' field ErrIncOpMissingInc = errors.New("inc operation missing 'inc' field") // ErrIncOpInvalidType indicates inc operation 'inc' field must be a number ErrIncOpInvalidType = errors.New("inc operation 'inc' field must be a number") // ErrStrInsOpMissingPos indicates str_ins operation is missing 'pos' field ErrStrInsOpMissingPos = errors.New("str_ins operation missing 'pos' field") // ErrStrInsOpMissingStr indicates str_ins operation is missing 'str' field ErrStrInsOpMissingStr = errors.New("str_ins operation missing 'str' field") // ErrStrDelOpMissingPos indicates str_del operation is missing 'pos' field ErrStrDelOpMissingPos = errors.New("str_del operation missing 'pos' field") // ErrStrDelOpMissingFields indicates str_del operation is missing 'str' or 'len' field ErrStrDelOpMissingFields = errors.New("str_del operation missing 'str' or 'len' field") // ErrSplitOpMissingPos indicates split operation is missing 'pos' field ErrSplitOpMissingPos = errors.New("split operation missing 'pos' field") // ErrMergeOpMissingPos indicates merge operation is missing 'pos' field ErrMergeOpMissingPos = errors.New("merge operation missing 'pos' field") // ErrTypeOpMissingValue indicates type operation is missing string 'value' field ErrTypeOpMissingValue = errors.New("type operation missing string 'value' field") // ErrTestTypeOpMissingType indicates test_type operation is missing 'type' field ErrTestTypeOpMissingType = errors.New("test_type operation missing 'type' field") // ErrTestStringOpMissingStr indicates test_string operation is missing 'str' field ErrTestStringOpMissingStr = errors.New("test_string operation missing 'str' field") // ErrTestStringLenOpMissingLen indicates test_string_len operation is missing 'len' field ErrTestStringLenOpMissingLen = errors.New("test_string_len operation missing 'len' field") // ErrContainsOpMissingValue indicates contains operation is missing 'value' field ErrContainsOpMissingValue = errors.New("contains operation missing 'value' field") // ErrEndsOpMissingValue indicates ends operation is missing 'value' field ErrEndsOpMissingValue = errors.New("ends operation missing 'value' field") // ErrStartsOpMissingValue indicates starts operation is missing 'value' field ErrStartsOpMissingValue = errors.New("starts operation missing 'value' field") // ErrMatchesOpMissingValue indicates matches operation is missing 'value' field ErrMatchesOpMissingValue = errors.New("matches operation missing 'value' field") // ErrLessOpMissingValue indicates less operation is missing 'value' field ErrLessOpMissingValue = errors.New("less operation missing 'value' field") // ErrMoreOpMissingValue indicates more operation is missing 'value' field ErrMoreOpMissingValue = errors.New("more operation missing 'value' field") // ErrAndOpMissingApply indicates and operation is missing 'apply' field ErrAndOpMissingApply = errors.New("and operation missing 'apply' field") // ErrOrOpMissingApply indicates or operation is missing 'apply' field ErrOrOpMissingApply = errors.New("or operation missing 'apply' field") // ErrNotOpMissingApply indicates not operation is missing 'apply' field ErrNotOpMissingApply = errors.New("not operation missing 'apply' field") // ErrValueNotObject indicates value is not an object ErrValueNotObject = errors.New("value is not an object") // ErrCodecOpUnknown indicates unknown operation ErrCodecOpUnknown = errors.New("unknown operation") )
Functions ¶
func Decode ¶
func Decode(operations []map[string]interface{}, options internal.JSONPatchOptions) ([]internal.Op, error)
Decode converts JSON operations to Op instances.
func DecodeJSON ¶
DecodeJSON converts JSON bytes to Op instances.
func DecodeOperations ¶ added in v0.5.0
func DecodeOperations(operations []internal.Operation, options internal.JSONPatchOptions) ([]internal.Op, error)
DecodeOperations converts Operation structs to Op instances using json/v2
func EncodeJSON ¶
EncodeJSON converts operations to JSON bytes.
func OperationToOp ¶
func OperationToOp(operation map[string]interface{}, options internal.JSONPatchOptions) (internal.Op, error)
OperationToOp converts JSON operation to Op instance.
func OperationToPredicateOp ¶
func OperationToPredicateOp(operation map[string]interface{}, options internal.JSONPatchOptions) (internal.Op, error)
OperationToPredicateOp converts JSON operation to PredicateOp instance.
Types ¶
type CompactOperation ¶
type CompactOperation = internal.CompactOperation
CompactOperation represents a compact format operation.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder provides JSON patch decoding functionality with configurable options.
func NewDecoder ¶
func NewDecoder(options internal.JSONPatchOptions) *Decoder
NewDecoder creates a new Decoder with the given options.
type Encoder ¶
type Encoder struct{}
Encoder provides JSON patch encoding functionality.
type Operation ¶
Operation represents a JSON Patch operation in JSON format. This unified structure supports all standard and extended operation internal.
type Options ¶
type Options struct {
// CreateMatcher creates a regex matcher function for pattern matching operations
CreateMatcher func(pattern string, ignoreCase bool) func(string) bool
}
Options represents configuration options for JSON codec operations. Provides configurable regex matcher creation for matches operations.
type PatchOptions ¶ added in v0.4.3
type PatchOptions = internal.JSONPatchOptions
PatchOptions contains options for JSON Patch operations.