Comments (12)
There is no consensus for ["first", "second", "third", "fourth", "fifth"][3::-1]
so far, but certainly a "productive" majority (as in non-empty responses) for the Python way: https://cburgmer.github.io/json-path-comparison/results/array_slice_with_open_end_and_negative_step.html
from json-path-comparison.
For me the best argument so far was "follow what Python is doing". For many developers that would probably be the least surprise. If we have another widely adopted implementation out there then let's put it on the table.
from json-path-comparison.
Unfortunately, those old 2.0 docs are silent about what happens when stride < 0
. Experimentally, Python 3 seems to adopt the "forwards A" interpretation:
$ python3
>>> ["first", "second", "third", "fourth", "fifth"][3:0:-1]
['fourth', 'third', 'second']
>>> ["first", "second", "third", "fourth", "fifth"][3:-1:-1]
[]
>>> ["first", "second", "third", "fourth", "fifth"][3::-1]
['fourth', 'third', 'second', 'first']
>>> ["first", "second", "third", "fourth", "fifth"][:0:-1]
['fifth', 'fourth', 'third', 'second']
from json-path-comparison.
I'm not aware of other open questions, so I think it's ok to change the implementation. As a cross-check, if you bump yaml-jsonpath, its behaviour should agree with what's needed here.
from json-path-comparison.
Got it, currently my implementation does not support negative step, there is a open issue to implement it, but I will freeze and wait a little bit.
from json-path-comparison.
Thanks for the thorough analysis.
I added another comparison Array slice with negative step and start greater than end.
I believe at the time of creating the query no implementation was returning anything meaningful for that, so I did not include it.
One more datapoint (and something users would compare to?):
$ python3
>>> ["first", "second", "third", "forth", "fifth"][0:3:-2]
[]
>>> ["first", "second", "third", "forth", "fifth"][3:0:-2]
['forth', 'second']
from json-path-comparison.
As for me, I've just used python (which seems to be used as a basis for ES4 slice proposal) spec/CLI to verify if my implementation works the same.
from json-path-comparison.
Old 2.0 docs seem to contain a bit more info.
from json-path-comparison.
I think at this stage I would try to follow the Python implementation, minus throwing an error if nothing was found, because that's up to the underlying implementation to decide.
If we agree, are there any open questions, or do we just need to make the change in the implementation?
from json-path-comparison.
Sorry for the late interaction, but Backwards seems to have advantages:
- All rules that it's applied when step is positive and already have a consensus could be applied.
- The only thing the user need to know is the direction that the operation would occur.
from json-path-comparison.
@cleidiano I initially adopted the Backwards approach in my implementation because of the advantages you describe. But I changed my mind becauset the Backwards behaviour is probably unintuitive to programmers familiar with for
loops. I switched to Forwards A.
from json-path-comparison.
Closing this, at it seems we are happy with the way Proposal A is implementing this.
from json-path-comparison.
Related Issues (20)
- Is it possible to provide JSONPath test cases based on consensus results HOT 7
- Show footnote 4 if applicable on the query detail page
- Need test for filter expression checking for local key in array with a null value
- Alignment with spec in its current state (a report) HOT 7
- Incorporating and merging with the compliance test suite HOT 3
- Add nimma
- Include github.com/SteelBridgeLabs/jsonpath HOT 1
- Failing build of Java implementations in the docker container HOT 1
- Add serde_json_path HOT 2
- Add jpt HOT 2
- Bump JsonPath.Net to v1.0.0 HOT 3
- Comparing dotNET_JsonPathLib questionable
- Project governance HOT 7
- Link to reference implementation
- Support for path axis navigation HOT 11
- Issue with display of queries containing the * character HOT 1
- Expand on type of consensus HOT 2
- Tests for root reference in filter expressions. HOT 3
- Analysis HOT 2
- provide key for table contents HOT 8
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 json-path-comparison.