-
Notifications
You must be signed in to change notification settings - Fork 120
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
equivalent to jolt recursivelySquashNulls #340
Comments
I asked this question above but no answer which Im not sure why. If you come from Jolt background you have used this function and though it doenst work perfectly it helps sometimes and its good to have as an option. I started learning JSLT couple of days ago and it caught my interest. I can see cases where jstl can be better option than jolt and might simplify things. Performance I'm not sure though, I made comparison using Nifi and ran both spec on the same input to produce the same output and jolt always had the a little bit of edge. Regarding the above question here is what I was able to come up with and I hope I was successful:
Input:
squashNullsRecursive(.) |
I didn't answer because I don't have time to write this function from scratch. You're on the right trick, but in the top level of your function I'd use |
Can you please give an example for the simplification. Im not sure what you mean by if and test. Thanks |
You know what an |
Sorry I still dont get it. I thought Im using if statement with For loop and I thought this is the clean way per documentation. I know what if statement is. I might be slow and not as smart as you are but I know I can write better flatten-object than yours ;) |
This one works
It could be reduced to a simpler The last two replacement patterns can be collapsed into "," followed by either Or whichever mechanism there is. It works on RegexPlanet, see https://www.regexplanet.com/share/index.html?share=yyyyf6v7w2d I am aware this is not what @samer1977 asked for. |
I checked, see https://github.com/schibsted/jslt/blob/master/core/src/main/java/com/schibsted/spt/data/jslt/impl/BuiltinFunctions.java#L931 Java Regexp Pattern are used internally, but they do not support positional patterns. |
string replace? that looks scary from performance perspective but I guess I need to do some testing and find out |
My original algorithm did not support an initial property of an object being null.
Better performance, right ? This one does now support initial nulls in objects:
Tested on this input: {
"w": null,
"x": "x1",
"y": "y2",
"z": {
"z1": "z11",
"z2": null,
"z3": [
1,
{
"zzz": "skid",
"zzz1": null
},
2
]
}
} |
@samer1977 [ null, 2, 7, { "a": 1, "b": 2 }] Should that null be dropped ? My algorithm only drops attributes that are null. |
Hi,
Im coming from jolt background and now finding myself to learn jslt because apache nifi introduced new json transformation using jslt and I'm interested in learning to see if I can get the best of both world. Its totally different mind set but I can see how close its to Xquery in xml. I'm surprised that no one has asked this because this is common problem in json transformation when you want to get rid of all null values. Jolt has created function called recursivelySquashNulls that will remove all nulls in nested json recursively but I could not find something similar in jslt. Can someone please write me the spec for it in jslt? I spent the whole day trying to figure it out but its not that easy specially when your nested object is either complex object or array of complex object or even array of simple types. I would like to see if jslt can address all scenarios in not so much convoluted spec.
Thanks
The text was updated successfully, but these errors were encountered: