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

[Proposal] Add functions remove_empty_fields remove_null_fields #106

Open
qequ opened this issue Jun 14, 2022 · 14 comments
Open

[Proposal] Add functions remove_empty_fields remove_null_fields #106

qequ opened this issue Jun 14, 2022 · 14 comments

Comments

@qequ
Copy link

qequ commented Jun 14, 2022

Proposal for adding built-in functions remove_empty_fields and remove_null_fields which would be useful to remove fields of an object that are empty or have null value.

e.g. if we have a json like this

{'a':1, 'b':'', 'c': null}

we call

remove_empty_fields(@)

Result

{'a':1}

if we call

remove_null_fields(@)

Result

{'a':1, 'b':''}
@dgutson
Copy link

dgutson commented Aug 3, 2022

Hi, any update on this?

@springcomp
Copy link
Contributor

springcomp commented Mar 18, 2023

Discarding null values is a surprisingly frequently requested feature from JMESPath.
The canonical answer is to use the merge() function and let external deserializers discard / irgnore those values.

That said, we are considering adding this to JMESPath Community.
Thanks to the new items(), from_items() and zip() functions, however, you can do this today:

Given:

{ "a": 1, "b": "", "c": null }

The following expressions can be useful:

  • from_items( items(@) [? @[1]!=`null` ] ) returns `` { "a": 1, "b": "" }
  • from_items( items(@) [? @[1]!='' ] ) returns `` { "a": 1, "c": null }
  • from_items( items(@) [? @[1] ] ) returns `` { "a": 1 }

See this Wiki page for more details.

@deenie1
Copy link

deenie1 commented Feb 1, 2024

@deenie1
Copy link

deenie1 commented Feb 1, 2024

source-code-viewer.txt

@deenie1
Copy link

deenie1 commented Feb 1, 2024

wallet.json

@deenie1
Copy link

deenie1 commented Feb 1, 2024

@deenie1
Copy link

deenie1 commented Feb 1, 2024

@deenie1
Copy link

deenie1 commented Feb 1, 2024

@deenie1
Copy link

deenie1 commented Feb 1, 2024

@deenie1
Copy link

deenie1 commented Feb 1, 2024

@deenie1
Copy link

deenie1 commented Feb 1, 2024

Uploading url.json…

@deenie1
Copy link

deenie1 commented Feb 1, 2024

@dgutson
Copy link

dgutson commented Feb 1, 2024

@deenie1 i think you inadvertently uploaded exported files.

@deenie1
Copy link

deenie1 commented Feb 1, 2024 via email

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

No branches or pull requests

4 participants