Value Iteration
doganulus opened this issue · comments
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.
This could be implemented in an example first. What is the motivating use-case?
Why specifically depth-first? Why not breadth-first? What's the use case? I agree with Vinnie, this sounds like an example.
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.
@doganulus I think you should write it as an example contribution to Boost.JSON
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?