golang implementation of IETF RFC6901: JSON Pointer defines a string syntax for identifying a specific value within a JavaScript Object Notation (JSON) document.
install with:
go get -u github.com/qri-io/jsonpointer
Here's a quick example pulled from the godoc:
import (
"encoding/json"
"fmt"
"github.com/qri-io/jsonpointer"
)
var document = []byte(`{
"foo": {
"bar": {
"baz": [0,"hello!"]
}
}
}`)
func main() {
parsed := map[string]interface{}{}
// be sure to handle errors in real-world code!
json.Unmarshal(document, &parsed)
// parse a json pointer. Pointers can also be url fragments
// the following are equivelent pointers:
// "/foo/bar/baz/1"
// "#/foo/bar/baz/1"
// "http://example.com/document.json#/foo/bar/baz/1"
ptr, _ := jsonpointer.Parse("/foo/bar/baz/1")
// evaluate the pointer against the document
// evaluation always starts at the root of the document
got, _ := ptr.Eval(parsed)
fmt.Println(got)
// Output: hello!
}
MIT
Contributions & Issues are more than welcome! Everything happens over on this repo's github page