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) First() interface{}
- func (j *JSONQ) From(node string) *JSONQ
- func (j *JSONQ) FromString(str string) *JSONQ
- func (j *JSONQ) Get() interface{}
- func (j *JSONQ) GroupBy(property string) *JSONQ
- func (j *JSONQ) JSONString(json string) *JSONQ
- func (j *JSONQ) Last() interface{}
- 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) Offset(offset int) *JSONQ
- func (j *JSONQ) Only(properties ...string) interface{}
- 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) 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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) 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) 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) 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) More ¶
More provides the functionalities to query over the resultant data. See https://github.com/thedevsaddam/gojsonq/wiki/Queries#More
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) Reset ¶
Reset resets the current state of JSON instance and make a fresh object with the original json content
func (*JSONQ) SortBy ¶
SortBy sorts an array default ascending order, pass "desc" for descending order
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) 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) 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 (.)