jmespath.site icon indicating copy to clipboard operation
jmespath.site copied to clipboard

[Proposal] Add functions `remove_empty_fields` `remove_null_fields`

Open qequ opened this issue 3 years ago • 14 comments

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':''}

qequ avatar Jun 14 '22 18:06 qequ

Hi, any update on this?

dgutson avatar Aug 03 '22 18:08 dgutson

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.

springcomp avatar Mar 18 '23 06:03 springcomp

Uploading json-to-base64-converter.txt…

deenie1 avatar Feb 01 '24 16:02 deenie1

wallet.json

deenie1 avatar Feb 01 '24 16:02 deenie1

Uploading json-decode-online.json…

deenie1 avatar Feb 01 '24 16:02 deenie1

Uploading export-verified-contractaddress-opensource-license (1).csv…

deenie1 avatar Feb 01 '24 16:02 deenie1

Uploading source-code-viewer.txt…

deenie1 avatar Feb 01 '24 16:02 deenie1

Uploading export-verified-contractaddress-opensource-license.csv…

deenie1 avatar Feb 01 '24 16:02 deenie1

Uploading export-address-token-0xc0e6ad13bd58413ed308729b688d601243e1cf77.csv…

deenie1 avatar Feb 01 '24 16:02 deenie1

Uploading url.json…

deenie1 avatar Feb 01 '24 16:02 deenie1

Uploading json-to-base64-converter (1).txt…

deenie1 avatar Feb 01 '24 16:02 deenie1

@deenie1 i think you inadvertently uploaded exported files.

dgutson avatar Feb 01 '24 17:02 dgutson

Apologies I don't have any clue what I'm doing? I did not evens no I did what u said I did, sorry. Sent from my Huawei Mobile-------- Original Message --------Subject: Re: [jmespath/jmespath.site] [Proposal] Add functions remove_empty_fields remove_null_fields (Issue #106)From: Daniel Gutson To: "jmespath/jmespath.site" CC: Nixx ,Mention @deenie1 i think you inadvertently uploaded exported files.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

deenie1 avatar Feb 01 '24 18:02 deenie1