I want to extract the names as an array like below, and use this further for further processing.
["John", "Nick", "Jack", "Tom"]
Any idea how to do this? I did try running the json through a repeat, and assigning the names to another variable and outputting it prints both key-value pair, not just the value.
Wish json & array processing was simpler and easy in wappler on server side, it has always been a mystery! Any help will be very appreciated!
Hey. So I try not to ask too many questions as to why developers do things, but I gotta ask…are you sure this is the best way to handle all this? I mean, you are starting with hidden inputs containing json, and then trying to manipulate that json on the server…can you not just send these values in as arrays so you can just use the tools available? Anytime I spend a lot of time on something, it inevitably exposes that I have a root problem that needs to be addressed/restructured.
At any rate…the values you are showing for elements within your all_filters list do not represent true json - the key should always be in double quotes. So filter should be “filter”. Is that triggering the error, not sure.
Thanks mate. I will definitely re-look at the solution design, but long story short, the all_filters is part of a larger form submission (i agree it's not a json, it's an array of objects) and I have to dynamically build multiple elastic-search queries (in true json format).
I really want to understand why your suggestion is not working and what's the underlying difference. I did a thorough search on the forum and noticed, you have dealt with similar scenario here.. and patrick's solution seemed to work for you.
The all_filters at my end is part of a repeat in a server action, while yours seems to be something returned from a query/api-call. And I also notice that the account_id in your above is not within double-quotes anyway.
My form submits the below filters (array of objects).
Then, using {{all_filters.groupBy('filter').keys()}}, I want to output an array like this ["Last 24 hours", "Last 48 hours", "Custom"], which is not working , may be @patrick can help when he is back.
This issue could be related to the below, I just want to make sure I raise this as a defect, if it is in fact one.
There is definitely a difference between repeating an array (returned by form-submission, db-query or api-call) using the same name versus using a custom-name.
If I repeat the above "filters" with the same name, I can output all the properties. But when I repeat the same "filters" using a custom-name like "all_filters", then I can't output the properties.
Either way, the above groupBy formula didn't work giving me the array of values.
I might have figured out what the problem is. My all_filters repeat loops through a couple of array-of-objects and one of them is not well-formed for the collections formatter to work on, hence spitting the error message.
See below:
image-1 has the filters (form-submission)
image-2 is the if/else and since I'm filtering out only those filters tagged true, I have a dummy comment in the else part
image-3, this else part is in fact outputting an empty array instead of not doing anything
How can I avoid this and have a pure "if" condition without "else" part?
When formatter is applied to the above all_filters, I get the below error: message: “Undefined index: filter”, which now makes sense as two of the arrays are empty without a filter key/value pair.