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: search for a key into a json document #631

Open
brizio73 opened this issue Sep 2, 2022 · 1 comment
Open

feature request: search for a key into a json document #631

brizio73 opened this issue Sep 2, 2022 · 1 comment

Comments

@brizio73
Copy link

brizio73 commented Sep 2, 2022

Hi everybody! sorry if this is not the right place, I actually cannot find a better place... I'll try to make it quick. I have been using libjansson for quite a while now (I think we are close to 10 years or so... - great library by the way) but just today I found myself in the need of a feature that I think is missing from the library.

It would be great if one could perform a quick search on a json document to verify if a certain key is present. In my use case, an application requires an information that might be present in a json document that can be requested to a web API (just an http request to a specific address). The document is very large, and the position of that particular key is not exactly known in advance. We could collect a few samples of this document to parse it exactly and dig into the hierarchy until we find it, but the server providing this information is not under our control and may change in the future, sending a slightly different json. That would require us to change the code that parses the received json.

What I was asking is an API that might look like this: jsont_t* json_find(json_t *document, const char *key);
that returns NULL if key is not found inside the document or a json_t object in case it founds the key. What happens if there are many instances of that key has to be defined... the API could return an array of json_t* or the function could work as strtok() (that requires multiple calls to advance in the search from the last positive result).

What do you think? Any chances to see this function implemented in future releases?

Thanks for reading!
Bye

@woodz-
Copy link

woodz- commented Sep 17, 2022

This is OSS, so go for a pull request. An approach was already delivered by your own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants