Skip to content

Enhance JSON filter to work on all indexes of an array #3131

Open
@tarunlalwani

Description

@tarunlalwani

Currently when we use json.filter on a array object, we need to always use an index

> user := {"roles": [{"code": "abc", "name": "tarun"},{"code": "def", "name": "tarun2"}]}
Rule 'user' defined in package repl. Type 'show' to see rules.
>
> json.filter(user, ["roles/0/code"])
{
  "roles": [
    {
      "code": "abc"
    }
  ]
}
>

It would be great if we can get something like a _ in filter so specifying that for an array index will give all elements of the array

> json.filter(user, ["roles/_/code"])
{
  "roles": [
    {
      "code": "abc"
    },
    {
      "code": "def"
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions