Documentation
¶
Overview ¶
Package jsonpointer provides a golang implementation for json pointers.
Index ¶
Examples ¶
Constants ¶
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 GetForToken ¶
GetForToken gets a value for a json pointer token 1 level deep
func SetForToken ¶
SetForToken gets a value for a json pointer token 1 level deep
Types ¶
type JSONPointable ¶
JSONPointable is an interface for structs to implement when they need to customize the json pointer process
type JSONSetable ¶
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 is a representation of a json pointer
func (*Pointer) DecodedTokens ¶
DecodedTokens returns the decoded tokens of this JSON pointer
func (*Pointer) Get ¶
Get uses the pointer to retrieve a value from a JSON document
Example ¶
var doc exampleDocument
if err := json.Unmarshal(testDocumentJSONBytes, &doc); err != nil { // populates doc
panic(err)
}
pointer, err := New("/foo/1")
if err != nil {
panic(err)
}
value, kind, err := pointer.Get(doc)
if err != nil {
panic(err)
}
fmt.Printf(
"value: %q\nkind: %v\n",
value, kind,
)
Output: value: "baz" kind: string
func (*Pointer) IsEmpty ¶
IsEmpty returns true if this is an empty json pointer.
This indicates that it points to the root document.
func (*Pointer) Set ¶
Set uses the pointer to set a value from a JSON document
Example ¶
var doc exampleDocument
if err := json.Unmarshal(testDocumentJSONBytes, &doc); err != nil { // populates doc
panic(err)
}
pointer, err := New("/foo/1")
if err != nil {
panic(err)
}
result, err := pointer.Set(&doc, "hey my")
if err != nil {
panic(err)
}
fmt.Printf("result: %#v\n", result)
fmt.Printf("doc: %#v\n", doc)
Output: result: &jsonpointer.exampleDocument{Foo:[]string{"bar", "hey my"}} doc: jsonpointer.exampleDocument{Foo:[]string{"bar", "hey my"}}