Skip to content

jPaths of arrays #144

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

Open
NPellet opened this issue Jun 9, 2014 · 0 comments
Open

jPaths of arrays #144

NPellet opened this issue Jun 9, 2014 · 0 comments
Labels

Comments

@NPellet
Copy link
Owner

NPellet commented Jun 9, 2014

Ok here's the problem.

Say you have an array of objects:
[ { id: 1, a: 'A'}, { id: 2, a: 'B'}, { id: 3, a: 'C'} ]

You want to get with jpaths the following output:
[ 1, 2, 3 ]
Because you're interested in the ids of each row for instance.

Currently there's no way to do it automatically. I suggest that instead of proposing elements 0,1,2,3 and 4 in the jpath selector, we add the option "all" (value=-1) which gives forces the array output.

Example

Source: [ { id: 1, a: 'A'}, { id: 2, a: 'B'}, { id: 3, a: 'C'} ]
with element.0.id it would give 1
with element.-1.id it would give [ 1, 2, 3 ]

Source:
[
{ id: 1, a: [ { a: 'A', b: 'B', c: 'C' }, { a: 'A2', b: 'B2', c: 'C2' } ] },
{ id: 2, a: [ { a: 'D', b: 'E', c: 'F' }, { a: 'D2', b: 'E2', c: 'F2' } ] ,
{ id: 3, a: [ { a: 'G', b: 'H', c: 'I' }, { a: 'G2', b: 'H2', c: 'I2' } ] }
]

with element.0.a it would give [ { a: 'A', b: 'B', c: 'C' } ]
with element.-1.a.0.a it would give [ 'A', 'D', 'G' ]
with element.-1.a.-1.a it would give [ [ 'A', 'A2' ], [ 'D', 'D2' ], [ 'G', 'G2' ] ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant