Q: Using transform operator to delete variable keys
See original GitHub issueHi,
I’m struggling to use the transform operator to delete a key without knowing its name (the string can’t be static in my use case). Is this possible? Can I use a @ context variable binding with transform operator in order to delete the matching element? Are there other alternative?
Here is my example where I’d want to delete any key/value object at any level in the hierarchy (the example is just one level) whose readOnly
property is true
.

Thanks, Fabrice
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to remove the key-value pairs corresponding to the given ...
In this article let us see how to remove key-value pairs corresponding to a given key in the object. Using delete operator. When...
Read more >Transformation script variables
Multiple variables can be used to define explicit mapping relationships in a transform map script.
Read more >7. Transforming Data - Q for Mortals
The $ operator is overloaded to parse strings into data of any type exactly as the q interpreter does. This overload is invoked...
Read more >Shell Parameter Expansion (Bash Reference Manual) - GNU.org
Omitting the colon results in a test only for a parameter that is unset. Put another way, if the colon is included, the...
Read more >Manipulating data - Ansible Documentation
In many cases, you need to do some complex operation with your variables, ... filters: used to change/transform data, used with the |...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@andrew-coleman I found one edge case that I wanted to address here, in the event that someone else stumbles on this thread.
This will fail on any data structure that contains arrays within it, I believe because
$each
presumes it’s always operating on objects (Argument 1 of function "each" does not match function signature
).I’ve handled that case (I think) with the following modification (available to test here):
I’m using a
$type
conditional test to decide whether to iterate through the values using$map
(in the case of an array), or proceed to$each
as usual. (I’m enclosing the return from$map
in square brackets to ensure that it doesn’t convert single-element arrays to objects.)@andrew-coleman Incredible — thanks so much for this. (And for the great work on JSONata!)