Skip to content
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

Add a filter() function that allow to selected keys and nested keys from an object #37

Open
ecerulm opened this issue Nov 8, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@ecerulm
Copy link
Contributor

ecerulm commented Nov 8, 2018

Given the input :

{
  "a": 1,
  "b": 2, 
  "c": {
     "d": 3,
     "e": 4
   }
}

I want the filter(myobj, ['.b', '.c.e']) to produce the output

{
  "b": 2, 
  "c": {
     "e": 4
   }
}

Note that is this different from [for (myobj) . if ('.b', '.c.e')] that would produce an array [2, 4]

@larsga larsga added the enhancement New feature or request label Nov 30, 2018
@larsga
Copy link
Collaborator

larsga commented Nov 30, 2018

Couldn't you just write [for (myobj) . if (.b or c.e)]?

@ecerulm
Copy link
Contributor Author

ecerulm commented Dec 4, 2018

But [for (myobj) . if ('.b', '.c.e')] would return an array [2,4] not an object.

I guess it's possible to use the Object for expressions to achieve filtering on the first level:

{for (myobj)  .key : .value if  .key == "b" }

but get's very cumbersome (or maybe I'm missing an obvious solution) when you want to select nested keys.

The obvious alternative to filter(myobj, ['.b', '.c.e'] is to write:

{
  "b": .b,
 "c": { "e": .c.e}
}

which is what I'm trying to avoid. I wanted a alternative syntax for this that is more concise just for the case when I'm selecting/dropping stuff without transforming the values.

@larsga
Copy link
Collaborator

larsga commented Dec 5, 2018

I missed that you want to extract part of the structure, and not just the values. My bad.

Ok, I need to think more about this.

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

No branches or pull requests

2 participants