Skip to content

Indexing an array #3

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

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