Documentation ¶
Index ¶
- func Exists(data []byte, keys ...string) bool
- func GetBool(data []byte, keys ...string) bool
- func GetBytes(data []byte, keys ...string) []byte
- func GetFloat64(data []byte, keys ...string) float64
- func GetInt(data []byte, keys ...string) int
- func GetString(data []byte, keys ...string) string
- func ParseBestEffort(s string) float64
- type Filter
- type Object
- type Operation
- type Parser
- type ParserPool
- type Query
- type Type
- type Value
- func (v *Value) Array() ([]*Value, error)
- func (v *Value) Bool() (bool, error)
- func (v Value) Check(request Query) error
- func (v *Value) Exists(keys ...string) bool
- func (v *Value) Float64() (float64, error)
- func (v *Value) Get(keys ...string) *Value
- func (v *Value) GetArray(keys ...string) []*Value
- func (v *Value) GetBool(keys ...string) bool
- func (v *Value) GetFloat64(keys ...string) float64
- func (v *Value) GetInt(keys ...string) int
- func (v *Value) GetObject(keys ...string) *Object
- func (v *Value) GetStringBytes(keys ...string) []byte
- func (v *Value) Int() (int, error)
- func (v Value) Keep(request Query) (string, error)
- func (v *Value) Object() (*Object, error)
- func (v Value) Retrieve(request Query) (string, error)
- func (v Value) Search(keys ...string) ([]interface{}, error)
- func (v *Value) String() string
- func (v *Value) StringBytes() ([]byte, error)
- func (v *Value) Type() Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exists ¶
Exists returns true if the field identified by keys path exists in JSON data.
Array indexes may be represented as decimal numbers in keys.
False is returned on error. Use Parser for proper error handling.
Parser is faster when multiple fields must be checked in the JSON.
func GetBool ¶
GetBool returns boolean value for the field identified by keys path in JSON data.
Array indexes may be represented as decimal numbers in keys.
False is returned on error. Use Parser for proper error handling.
Parser is faster for obtaining multiple fields from JSON.
func GetBytes ¶
GetBytes returns string value for the field identified by keys path in JSON data.
Array indexes may be represented as decimal numbers in keys.
nil is returned on error. Use Parser for proper error handling.
Parser is faster for obtaining multiple fields from JSON.
func GetFloat64 ¶
GetFloat64 returns float64 value for the field identified by keys path in JSON data.
Array indexes may be represented as decimal numbers in keys.
0 is returned on error. Use Parser for proper error handling.
Parser is faster for obtaining multiple fields from JSON.
func GetInt ¶
GetInt returns int value for the field identified by keys path in JSON data.
Array indexes may be represented as decimal numbers in keys.
0 is returned on error. Use Parser for proper error handling.
Parser is faster for obtaining multiple fields from JSON.
func GetString ¶
GetString returns string value for the field identified by keys path in JSON data.
Array indexes may be represented as decimal numbers in keys.
An empty string is returned on error. Use Parser for proper error handling.
Parser is faster for obtaining multiple fields from JSON.
func ParseBestEffort ¶
ParseBestEffort parses floating-point number s.
It is equivalent to strconv.ParseFloat(s, 64), but is faster.
0 is returned if the number cannot be parsed.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter is the type used for describe a operation of filtering
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object represents JSON object.
Object cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.
func (*Object) Get ¶
Get returns the value for the given key in the o.
Returns nil if the value for the given key isn't found.
The returned value is valid until Parse is called on the Parser returned o.
type Operation ¶
type Operation string
Operation is common possible operations in filters (=, !=, >, <, >=, <=, :).
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses JSON.
Parser may be re-used for subsequent parsing.
Parser cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.
type ParserPool ¶
type ParserPool struct {
// contains filtered or unexported fields
}
ParserPool may be used for pooling parsers for similarly typed JSONs.
func (*ParserPool) Get ¶
func (pp *ParserPool) Get() *Parser
Get returns a parser from pp.
The parser must be Put to pp after use.
func (*ParserPool) Put ¶
func (pp *ParserPool) Put(p *Parser)
Put returns p to pp.
p and objects recursively returned from p cannot be used after p is put into pp.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is a description of a Query in a graphql like request
func MustParseQuery ¶
MustParseQuery is parseQuery without error return. You should be sure of your query syntax !
func ParseQuery ¶
ParseQuery create a easy traversable structure from a graphql like query.
type Type ¶
type Type int
Type represents JSON type.
const ( // TypeNull is JSON null. TypeNull Type = 0 // TypeObject is JSON object type. TypeObject Type = 1 // TypeArray is JSON array type. TypeArray Type = 2 // TypeString is JSON string type. TypeString Type = 3 // TypeNumber is JSON number type. TypeNumber Type = 4 // TypeTrue is JSON true. TypeTrue Type = 5 // TypeFalse is JSON false. TypeFalse Type = 6 )
type Value ¶
type Value struct { Description string // contains filtered or unexported fields }
Value represents any JSON value.
Call Type in order to determine the actual type of the JSON value.
Value cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.
func (*Value) Array ¶
Array returns the underlying JSON array for the v.
The returned array is valid until Parse is called on the Parser returned v.
Use GetArray if you don't need error handling.
func (*Value) Bool ¶
Bool returns the underlying JSON bool for the v.
Use GetBool if you don't need error handling.
func (*Value) Exists ¶
Exists returns true if the field exists for the given keys path.
Array indexes may be represented as decimal numbers in keys.
func (*Value) Float64 ¶
Float64 returns the underlying JSON number for the v.
Use GetFloat64 if you don't need error handling.
func (*Value) Get ¶
Get returns value by the given keys path.
Array indexes may be represented as decimal numbers in keys.
nil is returned for non-existing keys path.
The returned value is valid until Parse is called on the Parser returned v.
func (*Value) GetArray ¶
GetArray returns array value by the given keys path.
Array indexes may be represented as decimal numbers in keys.
nil is returned for non-existing keys path or for invalid value type.
The returned array is valid until Parse is called on the Parser returned v.
func (*Value) GetBool ¶
GetBool returns bool value by the given keys path.
Array indexes may be represented as decimal numbers in keys.
false is returned for non-existing keys path or for invalid value type.
func (*Value) GetFloat64 ¶
GetFloat64 returns float64 value by the given keys path.
Array indexes may be represented as decimal numbers in keys.
0 is returned for non-existing keys path or for invalid value type.
func (*Value) GetInt ¶
GetInt returns int value by the given keys path.
Array indexes may be represented as decimal numbers in keys.
0 is returned for non-existing keys path or for invalid value type.
func (*Value) GetObject ¶
GetObject returns object value by the given keys path.
Array indexes may be represented as decimal numbers in keys.
nil is returned for non-existing keys path or for invalid value type.
The returned object is valid until Parse is called on the Parser returned v.
func (*Value) GetStringBytes ¶
GetStringBytes returns string value by the given keys path.
Array indexes may be represented as decimal numbers in keys.
nil is returned for non-existing keys path or for invalid value type.
The returned string is valid until Parse is called on the Parser returned v.
func (*Value) Int ¶
Int returns the underlying JSON int for the v.
Use GetInt if you don't need error handling.
func (*Value) Object ¶
Object returns the underlying JSON object for the v.
The returned object is valid until Parse is called on the Parser returned v.
Use GetObject if you don't need error handling.
func (*Value) String ¶
String returns string representation of the v.
The function is for debugging purposes only. It isn't optimized for speed.
Don't confuse this function with StringBytes, which must be called for obtaining the underlying JSON string for the v.
func (*Value) StringBytes ¶
StringBytes returns the underlying JSON string for the v.
The returned string is valid until Parse is called on the Parser returned v.
Use GetStringBytes if you don't need error handling.