jsonquery

package
v0.0.0-...-fe45b29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("key not found")
	ErrNullJSON    = errors.New("value of JSON key is null")
	ErrNotArray    = errors.New("JSON value is not an array")
	ErrNotObject   = errors.New("JSON value is not an object")
	ErrNotString   = errors.New("JSON value is not a string")
	ErrNotNumeric  = errors.New("JSON value is not a numeric")
	ErrNotInteger  = errors.New("JSON value is not an integer")
	ErrUnpacking   = errors.New("failed to unpack ajson node")
)
View Source
var Convertor = convertor{} //nolint:gochecknoglobals

Convertor provides common conversion methods from ajson to go types.

Functions

This section is empty.

Types

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query is a helpful wrapper of ajson library that adds errors when querying JSON payload.

Usage examples, where node is JSON parsed via ajson library:

->	Must get *int64:	jsonquery.New(node).Integer("num", false)
->	Optional *string:	jsonquery.New(node).String("text", true)
->	Nested array:		jsonquery.New(node, "your", "path", "to", "array").Array("list", false)

func New

func New(node *ajson.Node, zoom ...string) *Query

New constructs query searching for key. Extra keys are preceding forming a zoom path.

func (*Query) Array

func (q *Query) Array(key string, optional bool) ([]*ajson.Node, error)

func (*Query) ArraySize

func (q *Query) ArraySize(key string) (int64, error)

func (*Query) Integer

func (q *Query) Integer(key string, optional bool) (*int64, error)

func (*Query) IntegerWithDefault

func (q *Query) IntegerWithDefault(key string, defaultValue int64) (int64, error)

func (*Query) Object

func (q *Query) Object(key string, optional bool) (*ajson.Node, error)

func (*Query) Str

func (q *Query) Str(key string, optional bool) (*string, error)

func (*Query) StrWithDefault

func (q *Query) StrWithDefault(key string, defaultValue string) (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL