-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Wildcard filter: remove empty objects #1486
Comments
Hi @jshep321, Thank you very much for this explanation; I can clearly see what you want. On the one hand, what's the point of keeping the empty object if there is no desired value in it? @jshep321, why is this such a big deal to get the empty objects? Best regards, |
Good points @bblanchon... it is complex for sure. IMHO it's perfectly ok to change the structure of the (non-wanted parts of the) document after filtering. The core idea of a filter is to remove unwanted stuff and keep wanted stuff. Filtering out all undesired stuff saves resource -- RAM and CPU cycles. Otherwise we will have to re-process the filtered output, which makes the filtering step not really useful in this case. Since I don't see an easy way to remove it with the ArduinoJson library, I would have to introduce either a new mechanism/library or make my own. The more I think about it, I realize that I'm probably half-wrong in my idea of the filter; 1) correct: removing USER1's structure is desirable but 2) keeping the "associated user data" is likely incorrect (since I am not explicitly filtering on it). Regarding the ESP32: I'm starting with it because it's got more RAM/CPU -- I plan to scale down to smaller MCUs. Also, my user DB is much larger than 2 users. So the case of keeping "USER1" and it's empty structure in this example will be expanded both in depth of each user and number of users. Perhaps a filter bool option to prune unfiltered objects in the tree would be the best path? That way you would allow current users (especially arrays) to not worry about unexpected behavior, but allow use cases like mine keep the filter as a single processing step? |
@bblanchon FYI, here is an overview of the Google firebase (non-array) challenge explained in a much clearer way than I explained above. In order to search for the index of name "amanda" in that example, I would try a filter of but this would not work and I don't think there is a way in arduinojson to return the key "1" to then use to retrieve the wanted data. |
|
Yes, you caught me... I am trying to use your filter to do actual searching (on both keys and values). :) I can see a need to do this in a resource efficient way and your filter mechanism is so very close! |
I agree this would be a useful feature, but I don't think I'll be able to implement it any time soon. |
Hi,
I wrote a sample .ino to demonstrate the challenge from https://github.com/bblanchon/ArduinoJson/issues/1309 with descriptions in the serial printout. File is here: https://gist.github.com/jshep321/2b9ffb745edfa9dc121257656d811a07
Note that for the json format I would prefer an array for the "data" level, but the Google cloud database converts arrays to object automatically, so I'm a bit out of luck without restructuring the data or starting elsewhere!
Output from the program:
Help appreciated or else I might have to do wonky stuff to search and filter this json object.
Thanks!
The text was updated successfully, but these errors were encountered: