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"
)
vardocument= []byte(`{ "foo": { "bar": { "baz": [0,"hello!"] } }}`)
funcmain() {
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 documentgot, _:=ptr.Eval(parsed)
fmt.Println(got)
// Output: hello!
}MIT
Contributions & Issues are more than welcome! Everything happens over on this repo's github page