Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
elgs committed Jan 18, 2016
1 parent ad3da6f commit c2cb166
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gojq.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type JQ struct {
Data interface{}
}

// Create a new &JQ from a raw JSON string.
// NewStringQuery - Create a new &JQ from a raw JSON string.
func NewStringQuery(jsonString string) (*JQ, error) {
var data = new(interface{})
err := json.Unmarshal([]byte(jsonString), data)
Expand All @@ -24,18 +24,18 @@ func NewStringQuery(jsonString string) (*JQ, error) {
return &JQ{*data}, nil
}

// Create a &JQ from an interface{} parsed by json.Unmarshal
// NewQuery - Create a &JQ from an interface{} parsed by json.Unmarshal
func NewQuery(jsonObject interface{}) *JQ {
return &JQ{Data: jsonObject}
}

// Query against the JSON with the expression passed in. The exp is separated by dots (".")
func (this *JQ) Query(exp string) (interface{}, error) {
// Query queries against the JSON with the expression passed in. The exp is separated by dots (".")
func (jq *JQ) Query(exp string) (interface{}, error) {
paths, err := gosplitargs.SplitArgs(exp, "\\.", false)
if err != nil {
return nil, err
}
var context interface{} = this.Data
var context interface{} = jq.Data
for _, path := range paths {
if len(path) >= 3 && strings.HasPrefix(path, "[") && strings.HasSuffix(path, "]") {
// array
Expand Down

0 comments on commit c2cb166

Please sign in to comment.