Documentation ¶
Overview ¶
Package gojsonq provides a simple, elegant and fast ODM like API to access/query JSON document.
JSON document can be read from file, string or io.Reader. Accessing the value of json property or querying document is simple as the example below:
package main import "github.com/thedevsaddam/gojsonq" const json = `{"name":{"first":"Tom","last":"Hanks"},"age":61}` func main() { name := gojsonq.New().JSONString(json).Find("name.first") println(name.(string)) // Tom }
For more details, see the documentation and examples.
Index ¶
- type Decoder
- type DefaultDecoder
- type JSONQ
- func (j *JSONQ) Avg(property ...string) float64
- func (j *JSONQ) Copy() *JSONQ
- func (j *JSONQ) Count() int
- func (j *JSONQ) Distinct(property string) *JSONQ
- func (j *JSONQ) Error() error
- func (j *JSONQ) Errors() []error
- func (j *JSONQ) File(filename string) *JSONQ
- func (j *JSONQ) Find(path string) interface{}
- func (j *JSONQ) FindR(path string) (*Result, error)
- func (j *JSONQ) First() interface{}
- func (j *JSONQ) FirstR() (*Result, error)
- func (j *JSONQ) From(node string) *JSONQ
- func (j *JSONQ) FromString(str string) *JSONQ
- func (j *JSONQ) Get() interface{}
- func (j *JSONQ) GetR() (*Result, error)
- func (j *JSONQ) GroupBy(property string) *JSONQ
- func (j *JSONQ) JSONString(json string) *JSONQ
- func (j *JSONQ) Last() interface{}
- func (j *JSONQ) LastR() (*Result, error)
- func (j *JSONQ) Limit(limit int) *JSONQ
- func (j *JSONQ) Macro(operator string, fn QueryFunc) *JSONQ
- func (j *JSONQ) Max(property ...string) float64
- func (j *JSONQ) Min(property ...string) float64
- func (j *JSONQ) More() *JSONQ
- func (j *JSONQ) Nth(index int) interface{}
- func (j *JSONQ) NthR(index int) (*Result, error)
- func (j *JSONQ) Offset(offset int) *JSONQ
- func (j *JSONQ) Only(properties ...string) interface{}
- func (j *JSONQ) OnlyR(properties ...string) (*Result, error)
- func (j *JSONQ) OrWhere(key, cond string, val interface{}) *JSONQ
- func (j *JSONQ) Out(v interface{})
- func (j *JSONQ) Pluck(property string) interface{}
- func (j *JSONQ) PluckR(property string) (*Result, error)
- func (j *JSONQ) Reader(r io.Reader) *JSONQ
- func (j *JSONQ) Reset() *JSONQ
- func (j *JSONQ) Select(properties ...string) *JSONQ
- func (j *JSONQ) Sort(order ...string) *JSONQ
- func (j *JSONQ) SortBy(order ...string) *JSONQ
- func (j *JSONQ) String() string
- func (j *JSONQ) Sum(property ...string) float64
- func (j *JSONQ) Where(key, cond string, val interface{}) *JSONQ
- func (j *JSONQ) WhereContains(key string, val interface{}) *JSONQ
- func (j *JSONQ) WhereEndsWith(key string, val interface{}) *JSONQ
- func (j *JSONQ) WhereEqual(key string, val interface{}) *JSONQ
- func (j *JSONQ) WhereIn(key string, val interface{}) *JSONQ
- func (j *JSONQ) WhereLenEqual(key string, val interface{}) *JSONQ
- func (j *JSONQ) WhereLenNotEqual(key string, val interface{}) *JSONQ
- func (j *JSONQ) WhereNil(key string) *JSONQ
- func (j *JSONQ) WhereNotEqual(key string, val interface{}) *JSONQ
- func (j *JSONQ) WhereNotIn(key string, val interface{}) *JSONQ
- func (j *JSONQ) WhereNotNil(key string) *JSONQ
- func (j *JSONQ) WhereStartsWith(key string, val interface{}) *JSONQ
- func (j *JSONQ) WhereStrictContains(key string, val interface{}) *JSONQ
- func (j *JSONQ) Writer(w io.Writer)
- type OptionFunc
- type QueryFunc
- type Result
- func (r *Result) Bool() (bool, error)
- func (r *Result) BoolSlice() ([]bool, error)
- func (r *Result) Duration() (time.Duration, error)
- func (r *Result) DurationSlice() ([]time.Duration, error)
- func (r *Result) Float32() (float32, error)
- func (r *Result) Float32Slice() ([]float32, error)
- func (r *Result) Float64() (float64, error)
- func (r *Result) Float64Slice() ([]float64, error)
- func (r *Result) Int() (int, error)
- func (r *Result) Int16() (int16, error)
- func (r *Result) Int16Slice() ([]int16, error)
- func (r *Result) Int32() (int32, error)
- func (r *Result) Int32Slice() ([]int32, error)
- func (r *Result) Int64() (int64, error)
- func (r *Result) Int64Slice() ([]int64, error)
- func (r *Result) Int8() (int8, error)
- func (r *Result) Int8Slice() ([]int8, error)
- func (r *Result) IntSlice() ([]int, error)
- func (r *Result) Nil() bool
- func (r *Result) String() (string, error)
- func (r *Result) StringSlice() ([]string, error)
- func (r *Result) Time(layout string) (time.Time, error)
- func (r *Result) TimeSlice(layout string) ([]time.Time, error)
- func (r *Result) Uint() (uint, error)
- func (r *Result) Uint16() (uint16, error)
- func (r *Result) Uint16Slice() ([]uint16, error)
- func (r *Result) Uint32() (uint32, error)
- func (r *Result) Uint32Slice() ([]uint32, error)
- func (r *Result) Uint64() (uint64, error)
- func (r *Result) Uint64Slice() ([]uint64, error)
- func (r *Result) Uint8() (uint8, error)
- func (r *Result) Uint8Slice() ([]uint8, error)
- func (r *Result) UintSlice() ([]uint, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶ added in v1.6.0
Decoder provide contract to decode JSON using custom decoder
type DefaultDecoder ¶ added in v1.6.0
type DefaultDecoder struct{}
DefaultDecoder use json.Unmarshal to decode JSON
func (*DefaultDecoder) Decode ¶ added in v1.6.0
func (u *DefaultDecoder) Decode(data []byte, v interface{}) error
Decode decodes using json.Unmarshal
type JSONQ ¶
type JSONQ struct {
// contains filtered or unexported fields
}
JSONQ describes a JSONQ type which contains all the state
func (*JSONQ) Avg ¶
Avg returns average of values from array or from map using property
func (*JSONQ) Copy ¶
Copy returns a new fresh instance of JSONQ with the original copy of data so that you can do concurrent operation on the same data without being decoded again
func (*JSONQ) Count ¶
Count returns the number of total items. This could be a length of list/array/map
func (*JSONQ) Distinct ¶ added in v1.8.0
Distinct builds distinct value using provided attribute/column/property
func (*JSONQ) File ¶
File read the json content from physical file
func (*JSONQ) Find ¶
Find returns the result of a exact matching path
func (*JSONQ) FindR ¶
FindR returns the result as Result instance from the exact matching path
func (*JSONQ) FirstR ¶
FirstR returns the first element of a list as Result instance
func (*JSONQ) From ¶
From seeks the json content to provided node. e.g: "users.[0]" or "users.[0].name"
func (*JSONQ) FromString ¶
FromString reads the content from valid json/xml/csv/yml string
func (*JSONQ) GetR ¶
GetR return the query results as Result instance
func (*JSONQ) GroupBy ¶
GroupBy builds a chunk of exact matched data in a group list using provided attribute/column/property
func (*JSONQ) JSONString ¶
JSONString reads the json content from valid json string // Deprecated: this method will remove in next major release
func (*JSONQ) LastR ¶
LastR returns the last element of a list as Result instance
func (*JSONQ) Limit ¶ added in v1.4.0
Limit limits the number of records in result
func (*JSONQ) Macro ¶
Macro adds a new query func to the JSONQ
func (*JSONQ) Max ¶
Max returns maximum value from array or from map using property
func (*JSONQ) Min ¶
Min returns minimum value from array or from map using property
func (*JSONQ) More ¶
More provides the functionalities to query over the resultant data. See https://github.com/thedevsaddam/gojsonq/wiki/Queries#More
func (*JSONQ) Nth ¶
Nth returns the nth element of a list
func (*JSONQ) NthR ¶
NthR returns the nth element of a list as Result instance
func (*JSONQ) Offset ¶
Offset skips the number of records in result
func (*JSONQ) Only ¶
Only collects the properties from a list of object
func (*JSONQ) OnlyR ¶
OnlyR collects the properties from a list of object and return as Result instance
func (*JSONQ) OrWhere ¶
OrWhere builds an OrWhere clause, basically it's a group of AND clauses
func (*JSONQ) Out ¶ added in v1.9.0
func (j *JSONQ) Out(v interface{})
Out write the queried data to defined custom type
func (*JSONQ) Pluck ¶
Pluck build an array of vlaues form a property of a list of objects
func (*JSONQ) PluckR ¶
PluckR build an array of vlaues form a property of a list of objects and return as Result instance
func (*JSONQ) Reader ¶
Reader reads the json content from io reader
func (*JSONQ) Reset ¶
Reset resets the current state of JSON instance and make a fresh object with the original json content
func (*JSONQ) Select ¶ added in v1.1.0
Select use for selection of the properties from query result
func (*JSONQ) Sort ¶
Sort sorts an array default ascending order, pass "desc" for descending order
func (*JSONQ) SortBy ¶
SortBy sorts an array default ascending order, pass "desc" for descending order
func (*JSONQ) Sum ¶
Sum returns sum of values from array or from map using property
func (*JSONQ) Where ¶
Where builds a where clause. e.g: Where("name", "contains", "doe")
func (*JSONQ) WhereContains ¶
WhereContains satisfies Where clause which contains provided value(string)
func (*JSONQ) WhereEndsWith ¶
WhereEndsWith satisfies Where clause which ends with provided value(string)
func (*JSONQ) WhereEqual ¶
WhereEqual is an alias of Where("key", "=", val)
func (*JSONQ) WhereIn ¶
WhereIn is an alias for where("key", "in", []string{"a", "b"})
func (*JSONQ) WhereLenEqual ¶ added in v1.7.0
WhereLenEqual is an alias of Where("key", "leneq", val)
func (*JSONQ) WhereLenNotEqual ¶ added in v1.7.0
WhereLenNotEqual is an alias of Where("key", "lenneq", val)
func (*JSONQ) WhereNil ¶
WhereNil is an alias of Where("key", "=", nil)
func (*JSONQ) WhereNotEqual ¶
WhereNotEqual is an alias of Where("key", "!=", val)
func (*JSONQ) WhereNotIn ¶
WhereNotIn is an alias for where("key", "notIn", []string{"a", "b"})
func (*JSONQ) WhereNotNil ¶
WhereNotNil is an alias of Where("key", "!=", nil)
func (*JSONQ) WhereStartsWith ¶
WhereStartsWith satisfies Where clause which starts with provided value(string)
func (*JSONQ) WhereStrictContains ¶
WhereStrictContains satisfies Where clause which contains provided value(string). This is case sensitive
type OptionFunc ¶ added in v1.6.0
OptionFunc represents a contract for option func, it basically set options to jsonq instance options
func SetDecoder ¶ added in v1.6.0
func SetDecoder(u Decoder) OptionFunc
SetDecoder take a custom decoder to decode JSON
func SetSeparator ¶
func SetSeparator(s string) OptionFunc
SetSeparator set custom separator for traversing child node, default separator is DOT (.)
type QueryFunc ¶
QueryFunc describes a conditional function which perform comparison
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result represent custom type
func (*Result) BoolSlice ¶
BoolSlice assert the result to []bool
func (*Result) Duration ¶
Duration assert the result to time.Duration
func (*Result) DurationSlice ¶
DurationSlice assert the result to []time.Duration
func (*Result) Float32 ¶
Float32 assert the result to float32
func (*Result) Float32Slice ¶
Float32Slice assert the result to []float32
func (*Result) Float64 ¶
Float64 assert the result to 64
func (*Result) Float64Slice ¶
Float64Slice assert the result to []float64
func (*Result) Int16Slice ¶
Int16Slice assert the result to []int16
func (*Result) Int32Slice ¶
Int32Slice assert the result to []int32
func (*Result) Int64Slice ¶
Int64Slice assert the result to []int64
func (*Result) Int8Slice ¶
Int8Slice assert the result to []int8
func (*Result) IntSlice ¶
IntSlice assert the result to []int
func (*Result) String ¶
String assert the result to String
func (*Result) StringSlice ¶
StringSlice assert the result to []string
func (*Result) Time ¶
Time assert the result to time.Time
func (*Result) TimeSlice ¶
TimeSlice assert the result to []time.Time
func (*Result) Uint16 ¶
Uint16 assert the result to uint16
func (*Result) Uint16Slice ¶
Uint16Slice assert the result to []uint16
func (*Result) Uint32 ¶
Uint32 assert the result to uint32
func (*Result) Uint32Slice ¶
Uint32Slice assert the result to []uint32
func (*Result) Uint64 ¶
Uint64 assert the result to uint64
func (*Result) Uint64Slice ¶
Uint64Slice assert the result to []uint64
func (*Result) Uint8Slice ¶
Uint8Slice assert the result to []uint8