Skip to content

Indexing an array #3

Closed
Closed

Description

@ZipZamZappem

I want this:
[
{
"index": 0,
"name": "a",
"state": "up"
},
{
"index": 1,
"name": "b",
"state": "down"
},
{
"index": 2,
"name": "c",
"state": "up"
}
]

From this:
{
"people": [
{
"name": "a",
"state": {"name": "up"}
},
{
"name": "b",
"state": {"name": "down"}
},
{
"name": "c",
"state": {"name": "up"}
}
]
}

But there is no '@.index' to allow this to work:
people[].{"index":@.index,"name":name, "state":state.name}

I realize this is not strictly a query function but AFAIK the items in a JSON list are ordered so it would not be arbitrary to associate a fixed index to each item.

Is there already a way to get this information?

Activity

  1. jdevillard commented on Aug 14, 2018

    @jdevillard
    Collaborator

    Hello,

    this is not in the original specification but would be usefull.
    @.index could not be an option because we can't have an index property in the JSON Source.

    We will check what keyword we can add for this.

  2. ZipZamZappem commented on Aug 14, 2018

    @ZipZamZappem
    Author

    2 random thoughts: 'ndx' or 'pos'
    longshot: 'indice'

  3. ZipZamZappem commented on Aug 15, 2018

    @ZipZamZappem
    Author

    A colleague suggested: 'offset'

  4. springcomp commented on Apr 12, 2019

    @springcomp
    Collaborator

    Thanks for the feedback.
    I would first try an steer the official specification to include this before integrating non-official extensions.

  5. ZipZamZappem commented on Apr 12, 2019

    @ZipZamZappem
    Author

    How does one go about proposing changes to the official specification?

  6. springcomp commented on Aug 31, 2019

    @springcomp
    Collaborator

    I think you must head over to the official site and write a pull request to the spec.
    Similar to this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions