Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking change: Change how the recursive operator works
I found a bug in how the recursive operator works (thanks to issue 64). It was only using the latest selected result (not the whole array) to apply the recursive search on. Once this was fixed, two existing tests failed. Both using the same JsonPath `$.store..*[?(@..model == null)].color` on the following JSON document: { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95, "available": true }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99, "available": false }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99, "available": true }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99, "available": false } ], "bicycle": { "color": "red", "price": 19.95, "available": true, "model": null, "sku-number": "BCCLE-0001-RD" } }, "authors": [ "Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien" ], "Bike models": [ 1, 2, 3 ] } After a long analysis I have realized that the test was wrong. Let's break that down: 1. `$` selects the whole json. 2. `.store` selects the value for the key "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95, "available": true }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99, "available": false }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99, "available": true }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99, "available": false } ], "bicycle": { "color": "red", "price": 19.95, "available": true, "model": null, "sku-number": "BCCLE-0001-RD" } } 3. `..*` selects for all values recursively, all their children (this is equivalent to doing `.*` and then `.*.*` and then `.*.*.*` etc.). For the object in `$.store..*` it will return: [ { "color": "red", "price": 19.95, "available": true, "model": null, "sku-number": "BCCLE-0001-RD" }, "red", 19.95, true, null, "BCCLE-0001-RD", ... // the list of books, // all the book objects..., // all the properties for all the books... ] 4. Let's take the first result above and apply the next operation of the query: `[?(@..model == null)]`. This means "select the children that contain any field, recursively, with name 'model' and value null". The children of { "color": "red", "price": 19.95, "available": true, "model": null, "sku-number": "BCCLE-0001-RD" } are the following: [ "red", 19.95, true, null, "BCCLE-0001-RD" ] Neither of which have a member named "model", let alone with value null, yet the test expected a successful result for the query. The correct query would be `$.store..[?(@..model == null)].color` to avoid an extra step down with the `*` after the `..`. Having a Child Selection operation just after a Recursive Selection one was unsupported but this has been implemented as part of this commit.
- Loading branch information