Skip to content
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

Feature request: filter a number of occurence on a list #1598

Closed
sn0oz opened this issue Jun 26, 2021 · 2 comments
Closed

Feature request: filter a number of occurence on a list #1598

sn0oz opened this issue Jun 26, 2021 · 2 comments

Comments

@sn0oz
Copy link

sn0oz commented Jun 26, 2021

Would it be possible to filter a number of occurence on a list to reduce further the data size for APIs which don't support pagination ?

For example this JSON:

{
list: [
    { "number": 0 },
    { "number": 1 },
    { "number": 2 },
    { "number": 3 }
    ]
}

filtered with something like:
filter["list"][2]["number"] = true;

would result in:

{
list: [
    { "number": 0 },
    { "number": 1 }
    ]
}
@bblanchon
Copy link
Owner

Hi @sn0oz,

This feature was requested several times, but I never implemented it because I could not find a satisfying API.
See this older answer for details.

The API you suggest makes sense, but it's too limited and is inconsistent with the existing filter["list"][0]["number"] = true, which includes all the elements.
Moreover, because ArduinoJson uses a dense array (as opposed to sparsed arrays), if a user sets filter["list"][100]["number"] = true, it allocates an array of 100 elements, which is quite a waste of RAM.

A better solution would be to use a query language as I suggested in #1486 (comment).
I'm not against the idea, but I'm afraid this will be a huge work with very little return, and the executable would inflate significantly.

We could also use a predicate instead of a query or filter.
This could be as powerful as the query language but wouldn't require a new parser and keep the code small.
I had this idea on the back of my head for a long time, but I couldn't figure out an intuitive API.

For your particular issue, I think the "deserialization in chunks" technique provides a better solution.

Best regards,
Benoit

@sn0oz
Copy link
Author

sn0oz commented Jun 27, 2021

Hi Benoit, thanks for the detailed reply.
I understand your points, and will look at the deserialization in chuncks technique.
Thanks again for your great work on this library !

@sn0oz sn0oz closed this as completed Jun 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants