Documentation ¶
Index ¶
- Variables
- type Query
- func (q *Query) Array(key string, optional bool) ([]*ajson.Node, error)
- func (q *Query) ArraySize(key string) (int64, error)
- func (q *Query) Bool(key string, optional bool) (*bool, error)
- func (q *Query) BoolWithDefault(key string, defaultValue bool) (bool, error)
- func (q *Query) Integer(key string, optional bool) (*int64, error)
- func (q *Query) IntegerWithDefault(key string, defaultValue int64) (int64, error)
- func (q *Query) Object(key string, optional bool) (*ajson.Node, error)
- func (q *Query) Str(key string, optional bool) (*string, error)
- func (q *Query) StrWithDefault(key string, defaultValue string) (string, error)
- func (q *Query) TextWithDefault(key string, defaultValue string) (string, error)
Constants ¶
This section is empty.
Variables ¶
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") ErrNotBool = errors.New("JSON value is not a boolean") 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") )
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) -> Convert current obj to list: jsonquery.New(node).Array("", false)
func (*Query) Array ¶
Array returns list of nodes. Optional argument set to false will create error in case of missing value. Empty key is interpreter as "this", in other words current node.
func (*Query) ArraySize ¶
ArraySize returns the array size located under key. It is assumed that array value must be not null and present. Empty key is interpreter as "this", in other words current node.
func (*Query) Bool ¶
Bool returns boolean. Optional argument set to false will create error in case of missing value. Empty key is interpreter as "this", in other words current node.
func (*Query) BoolWithDefault ¶
func (*Query) Integer ¶
Integer returns integer. Optional argument set to false will create error in case of missing value. Empty key is interpreter as "this", in other words current node.
func (*Query) IntegerWithDefault ¶
func (*Query) Object ¶
Object returns json object. Optional argument set to false will create error in case of missing value. Empty key is interpreter as "this", in other words current node.
func (*Query) Str ¶
Str returns string. Optional argument set to false will create error in case of missing value. Empty key is interpreter as "this", in other words current node.