Comments (6)
That is interesting. Sounds like a bug that will need to be fixed.
from ojg.
Simple test example that shows this.
Query1 returns 1 item in the result. Query 2 returns no items in the result. The only difference is change from query of 'type' to '@type', both using the bracket notation.
Hope this helps.
func TestQuery2(t *testing.T) {
store := make(map[string]interface{})
jsondoc := `{
"item1": {
"id": "item1",
"type": "type1",
"@type": "attype1"
},
"item2": {
"id": "item2",
"type": "type2",
"@type": "attype2"
}
}`
query1 := `$[?(@['type']=="type1")]` // bracket notation without object literal
query2 := `$[?(@['@type']=="type1")]` // with object literal
err := json.Unmarshal([]byte(jsondoc), &store)
assert.NoError(t, err)
jpExpr, err := jp.ParseString(query1)
assert.NoError(t, err)
result := jpExpr.Get(store) // this returns one result as expected
assert.NotEmpty(t, result)
jpExpr, err = jp.ParseString(query2)
assert.NoError(t, err)
result = jpExpr.Get(store)
assert.NotEmpty(t, result) // this fails with empty result
}
from ojg.
Thanks, that helps.
from ojg.
I found the problem. query2
is checking for @type
being equal to "type1"
. There is no match for that in the json doc. There is a match for "attype1"
though. This worked for me:
func TestFilterAt(t *testing.T) {
jsondoc := `{
"item1": {
"id": "item1",
"type": "type1",
"@type": "attype1"
},
"item2": {
"id": "item2",
"type": "type2",
"@type": "attype2"
}
}`
store := oj.MustParseString(jsondoc)
x := jp.MustParseString(`$[?(@['@type']=="attype1")]`)
result := x.Get(store)
tt.Equal(t, 1, len(result))
}
That test has been added to the jp/get_test.go file in the project.
from ojg.
Arggh, that was a silly mistake with my test cases.
Sorry for wasting your time and thank you for looking into it.
ps: thank you again for a great library!
from ojg.
All good. It lets me know there are some users out there. :-)
from ojg.
Related Issues (20)
- Working with a collection of JSONPaths simultaneously? HOT 2
- Does JsonPath supports escaping? HOT 13
- Option to keep order of keys HOT 16
- Does support ”-“ HOT 1
- Parse '1,2,3' should not succeed HOT 3
- Expr.String() doesn't escape strings HOT 6
- Question: Using jp.Set() to set non-existent slice indices HOT 2
- Maybe a regression on path filters on version 1.18.0 HOT 3
- support for "json" tag in struct elements HOT 4
- Single or Multiple HOT 6
- Provides the length functionality HOT 2
- asm.cond doesn't evaluate expressions HOT 4
- recursive descent on object, unexpected results HOT 7
- Add float write format option HOT 1
- Array type with windowing like functionality? HOT 2
- Panic on setting a nil value on JSONPath HOT 3
- '' is not a valid operation at 16 in $..book[[email protected]] HOT 9
- oj.Unmarshal fails on arrays HOT 4
- Can I get a Normalized Path in JP? (ietf) HOT 13
- Add jp.Expr.Locate() HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ojg.