Documentation
¶
Index ¶
- Constants
- func IterateArray(ctx context.Context, r io.Reader) iter.Seq2[json.RawMessage, error]
- func Query(r io.Reader, path ...Kind) iter.Seq2[json.RawMessage, error]
- func QueryMany(r io.Reader, selectors ...Selector) error
- func Scan(in Input) (json.RawMessage, error)
- func ScanFrom[T string | []byte | *bufio.Reader](v T) (json.RawMessage, error)
- func TrimSpace(data []byte) []byte
- type ArrayIterator
- type Input
- type Kind
- type KindElement
- type KindValue
- type LexingError
- type Output
- type Path
- type Scanner
- type Selector
Examples ¶
Constants ¶
View Source
const ( KindString strKind = "string" KindNumber strKind = "number" KindBoolean strKind = "boolean" KindNull strKind = "null" )
View Source
const ( KindObject strKind = "object" KindName strKind = "name" )
View Source
const ErrMalformed errorkit.Error = "[ErrMalformed] malformed JSON"
View Source
const KindArray strKind = "array"
Variables ¶
This section is empty.
Functions ¶
func IterateArray ¶
func Query ¶
Query will turn the input reader into a json visitor that yields results when a path is matching. Think about it something similar as jq. It will not keep the visited json i n memory, to avoid problems with infinite streams.
Example ¶
package main
import (
"fmt"
"io"
"go.llib.dev/frameless/pkg/jsonkit/jsontoken"
)
func main() {
var body io.Reader
result := jsontoken.Query(body, jsontoken.KindArray, jsontoken.KindElement{})
for rawJSON, err := range result {
if err != nil {
fmt.Println(err.Error())
continue
}
fmt.Println(string(rawJSON))
}
}
func Scan ¶
func Scan(in Input) (json.RawMessage, error)
Scan scan a json raw message out from an input source.
Types ¶
type ArrayIterator ¶
type ArrayIterator struct {
Context context.Context
Input io.Reader
// contains filtered or unexported fields
}
func (*ArrayIterator) Close ¶
func (c *ArrayIterator) Close() error
func (*ArrayIterator) Decode ¶
func (c *ArrayIterator) Decode(ptr any) error
func (*ArrayIterator) Err ¶
func (c *ArrayIterator) Err() error
func (*ArrayIterator) Next ¶
func (c *ArrayIterator) Next() bool
func (*ArrayIterator) Value ¶
func (c *ArrayIterator) Value() json.RawMessage
type Input ¶
type Input interface {
iokit.RuneReader
iokit.RuneUnreader
iokit.ByteReader
}
type KindElement ¶ added in v0.304.0
type KindElement struct{ Index *int }
func (KindElement) Equal ¶ added in v0.304.1
func (e KindElement) Equal(oth Kind) bool
func (KindElement) String ¶ added in v0.304.1
func (e KindElement) String() string
type LexingError ¶ added in v0.304.0
func (LexingError) Error ¶ added in v0.304.0
func (err LexingError) Error() string
Click to show internal directories.
Click to hide internal directories.