thedevsaddam / gojsonq

A simple Go package to Query over JSON/YAML/XML/CSV Data
https://github.com/thedevsaddam/gojsonq/wiki
MIT License
2.18k stars 140 forks source link

add handling of objects to processQuery #57

Closed mrgleeco closed 5 years ago

mrgleeco commented 5 years ago

Change to enable queries on standalone objects. This makes queries like this possible:

j := gojsonq.New().JSONString(`{"name":{"first":"Tom","last":"Hanks"},"age":61}`)
ct := j.Where("age", ">=", 60).Where("name.last", "eq", "Hanks").Count() // 1
coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 307


Totals Coverage Status
Change from base Build 305: 0.0%
Covered Lines: 951
Relevant Lines: 951

💛 - Coveralls
coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 307


Totals Coverage Status
Change from base Build 305: 0.0%
Covered Lines: 951
Relevant Lines: 951

💛 - Coveralls
thedevsaddam commented 5 years ago

Please change the target branch from master to dev

thedevsaddam commented 5 years ago

How can I run the query ( SELECT * FROM . WHERE age < 30 )?

{
  "one":{
    "name":"John",
    "age":28
  },
  "two":{
    "name":"Jane",
    "age":30
  },
  "three":{
    "name":"Tom",
    "age":28
  }
}
j := gojsonq.New().FromString(data)
ct := j.Where("*.age", "=", 28).Get() // or more nested like. "*.*.age"
fmt.Println(ct)
mrgleeco commented 5 years ago

This functionality seems extra; orthogonal (additional?) to the proposed patch.

Are wildcards supported in Where? All docs illustrate example arg strings as key op val, not keymatch

This might be reasonable in future work; docs could illustrate the current behavior and its limits

thedevsaddam commented 5 years ago

Issue #24 had an example of querying objects. In this particular case you need something like pattern matching/other good solution. I'm not sure what would be the use case of using Where for single object

mrgleeco commented 5 years ago

the context is a single message object delivered in a queue (think pubsub or sns). In some cases it may be desirable to filterJSON. Use of the Count() can help guide further message handling

mrgleeco commented 5 years ago

ping - any interest in merging this?

thedevsaddam commented 5 years ago

As Where clause is unnecessary for a single object query, you can simply use the Find method go get the value. I'm closing this PR.

Thank you