jsonx

package
v0.0.0-...-d76c0ac Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound indicates that the specified node was not found.

Functions

func ApplyPatch

func ApplyPatch(target []byte, patchPath string) ([]byte, error)

ApplyPatch applies an RFC 6902 JSON patch to the target JSON blob.

Test operations are not supported.

Types

type Patch

type Patch []PatchOp

Patch is an RFC 6902 JSON patch.

type PatchOp

type PatchOp struct {
	Op    PatchOpType
	From  PatchPointer
	Path  PatchPointer
	Value interface{}
}

PatchOp is an RFC 6902 JSON patch operation.

func (*PatchOp) Apply

func (op *PatchOp) Apply(v *interface{}) error

Apply applies the patch. Apply returns ErrNotFound if From or Path are required and refer to a value that does not exist in v.

type PatchOpType

type PatchOpType string

PatchOpType is an RFC 6902 JSON patch operation type.

const (
	// PatchOpAdd is an RFC 6902 JSON patch add operation.
	PatchOpAdd PatchOpType = "add"
	// PatchOpRemove is an RFC 6902 JSON patch remove operation.
	PatchOpRemove PatchOpType = "remove"
	// PatchOpReplace is an RFC 6902 JSON patch replace operation.
	PatchOpReplace PatchOpType = "replace"
	// PatchOpCopy is an RFC 6902 JSON patch copy operation.
	PatchOpCopy PatchOpType = "copy"
	// PatchOpMove is an RFC 6902 JSON patch move operation.
	PatchOpMove PatchOpType = "move"
)

func (PatchOpType) NeedsFrom

func (op PatchOpType) NeedsFrom() bool

NeedsFrom returns true if the operation must include "from".

func (PatchOpType) NeedsPath

func (op PatchOpType) NeedsPath() bool

NeedsPath returns true if the operation must include "path".

type PatchPointer

type PatchPointer string

PatchPointer is an RFC 6901 JSON pointer.

func (PatchPointer) Parse

func (p PatchPointer) Parse() ([]string, error)

Parse parses the pointer, returning an array of names/indices.

type Schema

type Schema struct {
	AdditionalItems      *Schema             `json:"additionalItems,omitempty"`
	AdditionalProperties *Schema             `json:"additionalProperties,omitempty"`
	AllOf                []*Schema           `json:"allOf,omitempty"`
	AnyOf                []*Schema           `json:"anyOf,omitempty"`
	Default              interface{}         `json:"default,omitempty"`
	Definitions          map[string]*Schema  `json:"definitions,omitempty"`
	Dependencies         map[string][]string `json:"dependencies,omitempty"`
	Description          string              `json:"description,omitempty"`
	Embedded             []string            `json:"$embedded,omitempty"`
	Enum                 []string            `json:"enum,omitempty"`
	ExclusiveMaximum     bool                `json:"exclusiveMaximum,omitempty"`
	ExclusiveMinimum     bool                `json:"exclusiveMinimum,omitempty"`
	Format               string              `json:"format,omitempty"`
	Id                   string              `json:"id,omitempty"`
	Items                *Schema             `json:"items,omitempty"`
	MaxItems             int                 `json:"maxItems,omitempty"`
	MaxLength            int                 `json:"maxLength,omitempty"`
	MaxProperties        int                 `json:"maxProperties,omitempty"`
	Maximum              float64             `json:"maximum,omitempty"`
	MinItems             int                 `json:"minItems,omitempty"`
	MinLength            int                 `json:"minLength,omitempty"`
	MinProperties        int                 `json:"minProperties,omitempty"`
	Minimum              float64             `json:"minimum,omitempty"`
	MultipleOf           float64             `json:"multipleOf,omitempty"`
	Not                  *Schema             `json:"not,omitempty"`
	OneOf                []*Schema           `json:"oneOf,omitempty"`
	Order                int                 `json:"$order,omitempty"`
	Pattern              string              `json:"pattern,omitempty"`
	PatternProperties    map[string]*Schema  `json:"patternProperties,omitempty"`
	Properties           map[string]*Schema  `json:"properties,omitempty"`
	Ref                  string              `json:"$ref,omitempty"`
	Required             []string            `json:"required,omitempty"`
	Schema               string              `json:"$schema,omitempty"`
	Title                string              `json:"title,omitempty"`
	Type                 Schema_Type         `json:"type,omitempty"`
	UniqueItems          bool                `json:"uniqueItems,omitempty"`
}

type Schema_Type

type Schema_Type []SimpleTypes

Schema_Type Schema type.

func (Schema_Type) MarshalJSON

func (t Schema_Type) MarshalJSON() ([]byte, error)

func (*Schema_Type) UnmarshalJSON

func (t *Schema_Type) UnmarshalJSON(b []byte) error

type SimpleTypes

type SimpleTypes string
const (
	SimpleTypes_Array   SimpleTypes = "array"
	SimpleTypes_Boolean SimpleTypes = "boolean"
	SimpleTypes_Integer SimpleTypes = "integer"
	SimpleTypes_Null    SimpleTypes = "null"
	SimpleTypes_Number  SimpleTypes = "number"
	SimpleTypes_Object  SimpleTypes = "object"
	SimpleTypes_String  SimpleTypes = "string"
)

Jump to

Keyboard shortcuts

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