Documentation
¶
Overview ¶
Example ¶
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/dolmen-go/jsonptr"
"github.com/dolmen-go/jsonweb"
)
func main() {
r, err := os.Open("testdata/wikipedia-0.web.json")
if err != nil {
panic(err)
}
dec := json.NewDecoder(r)
var browser jsonweb.Browser
if err = dec.Decode(&browser); err != nil {
panic(err)
}
r.Close()
r, err = os.Open("testdata/wikipedia-0.json")
if err != nil {
panic(err)
}
err = browser.Parse(
`https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&prop=revisions|info&rvprop=user&rvlimit=10&format=json&formatversion=2`,
json.NewDecoder(r),
func(ptr jsonptr.Pointer, ctx *jsonweb.Context) error {
values, _ := json.Marshal(ctx.Values())
fmt.Printf("%s: %s\n", ptr, values)
return nil
},
)
if err != nil {
panic(err)
}
}
Output: /query/pages/0: {"title":"Main Page"} /query/pages/0/revisions/0: {"title":"Main Page","user":"The Blade of the Northern Lights"} /query/pages/0/revisions/1: {"title":"Main Page","user":"Bearcat"} /query/pages/0/revisions/2: {"title":"Main Page","user":"Bearcat"} /query/pages/0/revisions/3: {"title":"Main Page","user":"Optimist on the run"} /query/pages/0/revisions/4: {"title":"Main Page","user":"Ian.thomson"} /query/pages/0/revisions/5: {"title":"Main Page","user":"Ian.thomson"} /query/pages/0/revisions/6: {"title":"Main Page","user":"Alex Shih"} /query/pages/0/revisions/7: {"title":"Main Page","user":"TheDJ"} /query/pages/0/revisions/8: {"title":"Main Page","user":"TheDJ"} /query/pages/0/revisions/9: {"title":"Main Page","user":"Doc James"}
Index ¶
- type Browser
- func (browser *Browser) MarshalJSON() ([]byte, error)
- func (browser *Browser) Parse(url string, doc interface{}, visit ContextVisitor) error
- func (browser *Browser) Roots() []string
- func (browser *Browser) UnmarshalJSON(b []byte) error
- func (browser *Browser) WithVars(names []string) []*uritemplates.UriTemplate
- type BuildError
- type Context
- type ContextVisitor
- type ContextVisitorError
- type Extractor
- type ExtractorError
- type Map
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
func NewBrowser ¶
func (*Browser) MarshalJSON ¶
func (*Browser) Parse ¶
func (browser *Browser) Parse(url string, doc interface{}, visit ContextVisitor) error
func (*Browser) UnmarshalJSON ¶
func (*Browser) WithVars ¶
func (browser *Browser) WithVars(names []string) []*uritemplates.UriTemplate
type BuildError ¶
func (*BuildError) Error ¶
func (e *BuildError) Error() string
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
type ContextVisitor ¶
ContextVisitor is a callback that visits all contexts of a JSON-style document. The pointer is reused between calls, so it must be .Copy()ed if you need to keep it beyond the duraction of the visit call.
type ContextVisitorError ¶
type ContextVisitorError struct {
Err error
}
func (ContextVisitorError) Error ¶
func (e ContextVisitorError) Error() string
type Extractor ¶
type Extractor struct {
// contains filtered or unexported fields
}
Extractor allows to extract hierarchical points of interest in a JSON document.
func (*Extractor) UnmarshalJSON ¶
type ExtractorError ¶
func (*ExtractorError) Error ¶
func (e *ExtractorError) Error() string
Click to show internal directories.
Click to hide internal directories.