forked from mirror/gjson
Merge pull request #98 from thirstycoda/master
Added not like operator support to query
This commit is contained in:
commit
081192fa2e
|
@ -88,13 +88,14 @@ The dot and wildcard characters can be escaped with '\\'.
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also query an array for the first match by using `#[...]`, or find all matches with `#[...]#`.
|
You can also query an array for the first match by using `#[...]`, or find all matches with `#[...]#`.
|
||||||
Queries support the `==`, `!=`, `<`, `<=`, `>`, `>=` comparison operators and the simple pattern matching `%` operator.
|
Queries support the `==`, `!=`, `<`, `<=`, `>`, `>=` comparison operators and the simple pattern matching `%` (like) and `!%` (not like) operators.
|
||||||
|
|
||||||
```
|
```
|
||||||
friends.#[last=="Murphy"].first >> "Dale"
|
friends.#[last=="Murphy"].first >> "Dale"
|
||||||
friends.#[last=="Murphy"]#.first >> ["Dale","Jane"]
|
friends.#[last=="Murphy"]#.first >> ["Dale","Jane"]
|
||||||
friends.#[age>45]#.last >> ["Craig","Murphy"]
|
friends.#[age>45]#.last >> ["Craig","Murphy"]
|
||||||
friends.#[first%"D*"].last >> "Murphy"
|
friends.#[first%"D*"].last >> "Murphy"
|
||||||
|
friends.#[first!%"D*"].last >> "Craig"
|
||||||
```
|
```
|
||||||
|
|
||||||
## JSON Lines
|
## JSON Lines
|
||||||
|
|
4
gjson.go
4
gjson.go
|
@ -755,7 +755,7 @@ func parseArrayPath(path string) (r arrayPathResult) {
|
||||||
if i < len(path) {
|
if i < len(path) {
|
||||||
s = i
|
s = i
|
||||||
if path[i] == '!' {
|
if path[i] == '!' {
|
||||||
if i < len(path)-1 && path[i+1] == '=' {
|
if i < len(path)-1 && (path[i+1] == '=' || path[i+1] == '%') {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
} else if path[i] == '<' || path[i] == '>' {
|
} else if path[i] == '<' || path[i] == '>' {
|
||||||
|
@ -1099,6 +1099,8 @@ func queryMatches(rp *arrayPathResult, value Result) bool {
|
||||||
return value.Str >= rpv
|
return value.Str >= rpv
|
||||||
case "%":
|
case "%":
|
||||||
return match.Match(value.Str, rpv)
|
return match.Match(value.Str, rpv)
|
||||||
|
case "!%":
|
||||||
|
return !match.Match(value.Str, rpv)
|
||||||
}
|
}
|
||||||
case Number:
|
case Number:
|
||||||
rpvn, _ := strconv.ParseFloat(rpv, 64)
|
rpvn, _ := strconv.ParseFloat(rpv, 64)
|
||||||
|
|
|
@ -403,6 +403,10 @@ func TestBasic2(t *testing.T) {
|
||||||
if mtok.String() != "aaaa" {
|
if mtok.String() != "aaaa" {
|
||||||
t.Fatalf("expected %v, got %v", "aaaa", mtok.String())
|
t.Fatalf("expected %v, got %v", "aaaa", mtok.String())
|
||||||
}
|
}
|
||||||
|
mtok = get(basicJSON, `loggy.programmers.#[firstName !% "Bre*"].email`)
|
||||||
|
if mtok.String() != "bbbb" {
|
||||||
|
t.Fatalf("expected %v, got %v", "bbbb", mtok.String())
|
||||||
|
}
|
||||||
mtok = get(basicJSON, `loggy.programmers.#[firstName == "Brett"].email`)
|
mtok = get(basicJSON, `loggy.programmers.#[firstName == "Brett"].email`)
|
||||||
if mtok.String() != "aaaa" {
|
if mtok.String() != "aaaa" {
|
||||||
t.Fatalf("expected %v, got %v", "aaaa", mtok.String())
|
t.Fatalf("expected %v, got %v", "aaaa", mtok.String())
|
||||||
|
|
Loading…
Reference in New Issue