jspointer

package module
v0.0.0-...-82fadba Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: MIT Imports: 6 Imported by: 3

README

go-jspointer

Build Status

GoDoc

JSON pointer for Go

Features

  • Compile and match against Maps, Slices, Structs (or pointers to those)
  • Set values in each of those

Usage

p, _ := jspointer.New(`/foo/bar/baz`)
result, _ := p.Get(someStruct)

Credits

This is almost a fork of https://github.com/xeipuuv/gojsonpointer.

References

Name Notes
go-jsval Validator generator
go-jsschema JSON Schema implementation
go-jshschema JSON Hyper Schema implementation
go-jsref JSON Reference implementation

Documentation

Index

Constants

View Source
const (
	EncodedTilde = "~0"
	EncodedSlash = "~1"
	Separator    = '/'
)

Consntants used in jspointer package. Mostly for internal usage only

Variables

View Source
var (
	ErrInvalidPointer        = errors.New("invalid pointer")
	ErrCanNotSet             = errors.New("field cannot be set to")
	ErrSliceIndexOutOfBounds = errors.New("slice index out of bounds")
)

Errors used in jspointer package

Functions

This section is empty.

Types

type ErrNotFound

type ErrNotFound struct {
	Ptr string
}

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type JSONGetter

type JSONGetter interface {
	JSONGet(tok string) (interface{}, error)
}

type JSPointer

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

JSPointer represents a JSON pointer

func New

func New(path string) (*JSPointer, error)

New creates a new JSON pointer for given path spec. If the path fails to be parsed, an error is returned

func (JSPointer) Get

func (p JSPointer) Get(item interface{}) (interface{}, error)

Get applies the JSON pointer to the given item, and returns the result.

func (JSPointer) Set

func (p JSPointer) Set(item interface{}, value interface{}) error

Set applies the JSON pointer to the given item, and sets the value accordingly.

func (JSPointer) String

func (p JSPointer) String() string

String returns the stringified version of this JSON pointer

Jump to

Keyboard shortcuts

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