jsonpointer

package module
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: Apache-2.0 Imports: 7 Imported by: 136

README

gojsonpointer Build Status codecov

Slack Status license Go Reference Go Report Card

An implementation of JSON Pointer - Go language

Status

Completed YES

Tested YES

References

http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07

Note

The 4.Evaluation part of the previous reference, starting with 'If the currently referenced value is a JSON array, the reference token MUST contain either...' is not implemented.

Documentation

Index

Constants

View Source
const (
	// ErrPointer is an error raised by the jsonpointer package
	ErrPointer pointerError = "JSON pointer error"

	// ErrInvalidStart states that a JSON pointer must start with a separator ("/")
	ErrInvalidStart pointerError = `JSON pointer must be empty or start with a "` + pointerSeparator

	// ErrUnsupportedValueType indicates that a value of the wrong type is being set
	ErrUnsupportedValueType pointerError = "only structs, pointers, maps and slices are supported for setting values"
)

Variables

This section is empty.

Functions

func Escape

func Escape(token string) string

Escape escapes a pointer reference token string

func GetForToken

func GetForToken(document any, decodedToken string) (any, reflect.Kind, error)

GetForToken gets a value for a json pointer token 1 level deep

func SetForToken

func SetForToken(document any, decodedToken string, value any) (any, error)

SetForToken gets a value for a json pointer token 1 level deep

func Unescape

func Unescape(token string) string

Unescape unescapes a json pointer reference token string to the original representation

Types

type JSONPointable

type JSONPointable interface {
	JSONLookup(string) (any, error)
}

JSONPointable is an interface for structs to implement when they need to customize the json pointer process

type JSONSetable

type JSONSetable interface {
	JSONSet(string, any) error
}

JSONSetable is an interface for structs to implement when they need to customize the json pointer process

type Pointer

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

Pointer the json pointer reprsentation

func New

func New(jsonPointerString string) (Pointer, error)

New creates a new json pointer for the given string

func (*Pointer) DecodedTokens

func (p *Pointer) DecodedTokens() []string

DecodedTokens returns the decoded tokens

func (*Pointer) Get

func (p *Pointer) Get(document any) (any, reflect.Kind, error)

Get uses the pointer to retrieve a value from a JSON document

func (*Pointer) IsEmpty

func (p *Pointer) IsEmpty() bool

IsEmpty returns true if this is an empty json pointer this indicates that it points to the root document

func (*Pointer) Offset added in v0.20.0

func (p *Pointer) Offset(document string) (int64, error)

func (*Pointer) Set

func (p *Pointer) Set(document any, value any) (any, error)

Set uses the pointer to set a value from a JSON document

func (*Pointer) String

func (p *Pointer) String() string

Pointer to string representation function

Jump to

Keyboard shortcuts

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

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy