jsonpointer

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PointerString

func PointerString(parts ...string) string

PointerString returns the JSON Pointer string representation from the given parts. E.g. “#/path/to/field”.

Types

type JSONPointer

type JSONPointer struct {
	// URI is a parsed url.URL if the location is a URI. Fragment is always empty, as it is stored in Pointer field.
	URI *url.URL
	// FSPath is a filesystem path if the location is a local file path. Empty otherwise.
	FSPath string
	// Pointer keeps the JSON Pointer parts (i.e. URL fragment part) as a list of strings, url-unescaped.
	Pointer []string
}

JSONPointer represents the parsed JSON Pointer expression JSON Pointer IETF Draft, with additional support of the filesystem paths in location.

The JSON Pointer expression format is:

[location][#/path]

The “location” can be a URI or filesystem path. “Path” part is optional. Here are some JSON Pointer examples:

http://example.com/myfile?format=json#/path/to/field
/home/user/myfile.json#/path/to/field
#/path/to/field
https://example.com/schemas/myfile.json
file:///home/user/myfile.json

URI typically is stored in the URI field as parsed url.URL object. Filesystem path is stored in the FSPath field as string instead.

Typically, JSONPointer is used for representation of $ref expressions, read from the document, but may be used as usual URL.

func Parse

func Parse(uri string) (*JSONPointer, error)

Parse parses the JSON Pointer expression and returns the JSONPointer object. See JSONPointer type for more details.

func (JSONPointer) Location

func (r JSONPointer) Location() string

Location returns string representation of the location -- path to document without JSON pointer. If the location is a URI, returns the URI string. Otherwise, returns the FSPath.

func (JSONPointer) MatchPointer

func (r JSONPointer) MatchPointer(unescapedPointer []string) bool

MatchPointer returns true if pointers are equal, without considering their location. Receives the URL-unescaped pointer.

func (JSONPointer) PointerString

func (r JSONPointer) PointerString() string

PointerString returns the url-escaped JSON Pointer string representation without the location. E.g. “#/path/to/field”.

func (JSONPointer) String

func (r JSONPointer) String() (s string)

Jump to

Keyboard shortcuts

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