Documentation
¶
Index ¶
- Variables
- func ParseNode[T any](node *ajson.Node) (*T, error)
- type Query
- func (q *Query) ArrayOptional(key string) ([]*ajson.Node, error)
- func (q *Query) ArrayRequired(key string) ([]*ajson.Node, error)
- func (q *Query) BoolOptional(key string) (*bool, error)
- func (q *Query) BoolRequired(key string) (bool, error)
- func (q *Query) BoolWithDefault(key string, defaultValue bool) (bool, error)
- func (q *Query) IntegerOptional(key string) (*int64, error)
- func (q *Query) IntegerRequired(key string) (int64, error)
- func (q *Query) IntegerWithDefault(key string, defaultValue int64) (int64, error)
- func (q *Query) ObjectOptional(key string) (*ajson.Node, error)
- func (q *Query) ObjectRequired(key string) (*ajson.Node, error)
- func (q *Query) StrWithDefault(key string, defaultValue string) (string, error)
- func (q *Query) StringOptional(key string) (*string, error)
- func (q *Query) StringRequired(key 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 ¶
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) ArrayOptional ¶
ArrayOptional returns array of nodes if present. If the entity at the key path is not an array, an error is returned. Empty key is interpreted as "this", in other words a current node.
func (*Query) ArrayRequired ¶
ArrayRequired returns array of nodes. If the entity at the key path is not an array or is missing, an error is returned. Empty key is interpreted as "this", in other words a current node. Missing key returns ErrKeyNotFound. Null value returns ErrNullJSON.
func (*Query) BoolOptional ¶
BoolOptional returns boolean if present. If the entity at the key path is not a boolean, an error is returned. Empty key is interpreted as "this", in other words a current node.
func (*Query) BoolRequired ¶
BoolRequired returns boolean. If the entity at the key path is not a boolean or is missing, an error is returned. Empty key is interpreted as "this", in other words a current node. Missing key returns ErrKeyNotFound. Null value returns ErrNullJSON.
func (*Query) BoolWithDefault ¶
func (*Query) IntegerOptional ¶
IntegerOptional returns integer if present. If the entity at the key path is not an integer, an error is returned. Empty key is interpreter as "this", in other words current node.
func (*Query) IntegerRequired ¶
IntegerRequired returns integer. If the entity at the key path is not an integer or is missing, an error is returned. Empty key is interpreter as "this", in other words current node. Missing key returns ErrKeyNotFound. Null value returns ErrNullJSON.
func (*Query) IntegerWithDefault ¶
func (*Query) ObjectOptional ¶
ObjectOptional returns node object if present. If the entity at the key path is not a node object, an error is returned. Empty key is interpreter as "this", in other words current node.
func (*Query) ObjectRequired ¶
ObjectRequired returns node object. If the entity at the key path is not a node object or is missing, an error is returned. Empty key is interpreter as "this", in other words current node. Missing key returns ErrKeyNotFound. Null value returns ErrNullJSON.
func (*Query) StrWithDefault ¶
func (*Query) StringOptional ¶
StringOptional returns string if present. If the entity at the key path is not a string, an error is returned. Empty key is interpreted as "this", in other words a current node.
func (*Query) StringRequired ¶
StringRequired returns string. If the entity at the key path is not a string or is missing, an error is returned. Empty key is interpreted as "this", in other words a current node. Missing key returns ErrKeyNotFound. Null value returns ErrNullJSON.