Skip to content

jPaths of arrays #144

@NPellet

Description

@NPellet

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' ] ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions