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

Value Iteration #970

Open
doganulus opened this issue Jan 8, 2024 · 5 comments
Open

Value Iteration #970

doganulus opened this issue Jan 8, 2024 · 5 comments

Comments

@doganulus
Copy link
Contributor

I would like to start a discussion on having a class of value_iterator, which will be used to iterate over a value instance like visiting a tree in a depth-first manner.

Currently, we can iterate over array and object but I think a more general iterate functionality will be helpful for many applications. Also it would be nice that value supports generic iteration like other container classes.

I prefer each iteration to return a key-value pair of a JSON Pointer and value reference but I would like to ask your opinion regarding it and whether we can utilize the already implemented mechanisms/structures in the library.

@vinniefalco
Copy link
Member

vinniefalco commented Jan 8, 2024

This could be implemented in an example first. What is the motivating use-case?

@grisumbras
Copy link
Member

Why specifically depth-first? Why not breadth-first? What's the use case? I agree with Vinnie, this sounds like an example.

@doganulus
Copy link
Contributor Author

doganulus commented Jan 8, 2024

We use JSON values as the configuration object for programs. Sometimes, it is nice to list all the hierarchical key-value pairs flatly. I agree that this could be a good flatten example.

"/a/b/c": 12,
"/a/b/": "XYZ",
"/a/d": true,
"/a/e/c": 23,
"/a/f/c": 44,

But more importantly, iteration support would make it easier to use std::algorithm over JSON values. For example, I want to select all keys that satisfy a certain pattern such as /a/*/c, and filter/apply an operation on them. In this case, I will easily iterate over the JSON value and check whether the key matches the expression.

Depth-first is the most natural choice for me. I know there are multiple options to drive the iteration but one must be the default.

@vinniefalco
Copy link
Member

@doganulus I think you should write it as an example contribution to Boost.JSON

@grisumbras
Copy link
Member

Ok, so I am interested in this in a form of an example. I'm not exactly sold on this being general-purpose enough to be added to the library proper. BTW, have you thought about integration with Boost.Graph?

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

3 participants