Documentation
¶
Index ¶
- Constants
- func ErrMalformedF(format string, a ...any) error
- func IterateArray(ctx context.Context, r io.Reader) iter.Seq2[json.RawMessage, error]
- func Query(ctx context.Context, r io.Reader, path ...Kind) iter.Seq2[json.RawMessage, 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 KindObjectValue
- type Output
- type Path
- type Scanner
Examples ¶
Constants ¶
View Source
const ( KindArray strKind = "array" KindArrayValue strKind = "array-value" KindObject strKind = "object" KindObjectKey strKind = "object-key" KindString strKind = "string" KindNumber strKind = "number" KindBoolean strKind = "boolean" KindNull strKind = "null" )
View Source
const ErrMalformed errorkit.Error = "malformed json error"
Variables ¶
This section is empty.
Functions ¶
func ErrMalformedF ¶
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 (
"context"
"fmt"
"io"
"go.llib.dev/frameless/pkg/jsonkit/jsontoken"
)
func main() {
var ctx context.Context
var body io.Reader
result := jsontoken.Query(ctx, body, jsontoken.KindArray, jsontoken.KindArrayValue)
for rawJSON, err := range result {
if err != nil {
fmt.Println(err.Error())
continue
}
fmt.Println(string(rawJSON))
}
}
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 KindObjectValue ¶
type KindObjectValue struct {
// Key is the raw json data that represents the Key value
Key json.RawMessage
}
func (KindObjectValue) Equal ¶
func (k KindObjectValue) Equal(oth Kind) bool
func (KindObjectValue) String ¶
func (k KindObjectValue) String() string
Click to show internal directories.
Click to hide internal directories.