New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not to able to skip iteration in loop. #55
Comments
If you know array's length shorthand you can build a proper JsonPath expression that will filter the wanted positions, then apply it with #loop function: Input: { "test": [ { "id": 1, "dummy": "Item1", "ignored": "bla" }, { "id": 2, "dummy": "Item2", "ignored": "bla" }, { "id": 3, "dummy": "Item3", "ignored": "bla" }, { "id": 4, "dummy": "Item4", "ignored": "bla" } ]} Transformer: { "iteration": { "#loop($.test[1:3:1])": { "id": "#currentvalueatpath($.id)", "dummy": "#currentvalueatpath($.dummy)" } } } Result: { "iteration": [ { "id": 2, "dummy": "Item2" }, { "id": 3, "dummy": "Item3" } ] } |
Normally array's length is not fixed. It can be any number. Can i apply any condition with #currentIndex() or #lastIndex() in loop. |
Those functions are only available inside a #loop function, so you will end up with something generated for first and last element of the array, which as I understand is what you don't want. Besides what I mentioned, I don't see any other way of doing it as it stands. |
$.test[1:3:1] what it indicates. How it will skip first and last iteration. |
The first number is the start index (zero based), the second is the end index, the third is the step (optional) |
Currently #valueof function does not support multiple tokens as result, in other words, selecting multiple values and return the result as an array. Pull request #48 was an attempt to solve similar problems (#46 ) by allowing #valueof function to handle multiple results, but it was reverted back by #50. |
I want to transform Json that contains array. In one scenario, i want to skip iteration in loop. Is it possible to skip iteration on condition. As of now i want to skip first and last iteration
The text was updated successfully, but these errors were encountered: