This library is a Golang implementation of RFC6901 "JavaScript Object Notation (JSON) Pointer".
This library does not perform JSON encoding/decoding. Instead, you must provide data in the default Golang format for JSON data, namely:
bool, for JSON booleans
float64, for JSON numbers
string, for JSON strings
[]interface{}, for JSON arrays
map[string]interface{}, for JSON objects
nil for JSON null
(from the docs for encoding/json#Unmarshal
)
To create a JSON Pointer, use New
. To evaluate a pointer, use Eval
:
ptr, err := jsonpointer.New("/foo/1/bar")
data := map[string]interface{}{
"foo": []interface{}{
nil,
map[string]interface{}{
"bar": "hello, world",
},
},
}
val, err := ptr.Eval(&data)
fmt.Println(val) // outputs "hello, world"