Documentation ¶
Overview ¶
Package jsons converts JSON arrays into streams of objects.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
The Reader is an io.Reader that wraps another reader for the purposes of modifying a JSON stream. When the underlying reader provides a JSON array object ([obj, obj, ...]) this will be converted into a stream of newline terminated objects (obj\n obj\n obj\n) suitable for consumption by a bufio.Scanner or json.Decoder.
Example ¶
package main import ( "bytes" "encoding/json" "fmt" "io" "github.com/calmh/jsons" ) func main() { type Object struct { Foo string } input := bytes.NewBufferString(`[{"foo":"bar"}, {"foo":"baz"}]`) streamer := jsons.New(input) dec := json.NewDecoder(streamer) for { var res Object err := dec.Decode(&res) if err == io.EOF { break } if err != nil { fmt.Println("Error:", err) return } fmt.Printf("Read: %+v\n", res) } }
Output: Read: {Foo:bar} Read: {Foo:baz}
Click to show internal directories.
Click to hide internal directories.