-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Iterate over leafs of a JSON data structure: enrich the JSON pointer API #1054
Comments
Related: #837 |
Could you please provide more information on the described use case? Is the use of JSON Pointers fixed or would a different solution also be helpful? On iteration of nested elements, this may be helpful: https://stackoverflow.com/questions/45934851/c-nlohmann-json-how-to-iterate-find-a-nested-object/46630394#46630394 |
Use caseOK, so the context is the implementation of the widgets protocol for the C++ Jupyter kernel (see e.g. xwidgets). You can try it out live here: https://beta.mybinder.org/v2/gh/QuantStack/xwidgets/0.9.0?filepath=notebooks/xwidgets.ipynb The Jupyter widget protocol allows communicating binary frames in the messages to and from the frontend. The first frame is generally a JSON string and includes references to the binary frames {
"foo": {
"bar": @buffer_reference@1
},
"baz": 3,
"bat": @buffer_reference@0
} From which I need to extract an array of buffer paths: [["bat"], ["foo", "bar"]] Reversely, from the buffer paths, and the JSON Using JSON pointers?I could basically iterate in a similar way as in your example, but I figured that if the paths were encoded as json pointers, they it would be more elegant, especially for inserting back the So IMO, buffer paths would be more amenable if they had the full vector API.
In practice, using private inheritance with |
I am hesitant on adding an I would be happy for further discussion on this! |
Hum, this is not what I suggested! I merely suggested to give JSON pointer a general std::vector API. |
So this issue could be seen as a duplicate of #837? |
Maybe, although the idea of a Something like
is more natural than
also, having a special API based on |
Ok, I reopened #837. Let's join the discussion there. |
Duplicate of #837. |
Thanks |
Enriching the
json_pointer
APII noticed that the
json_pointer
class stored astd::vector<std::string>
internally.With private inheritance instead of composition, and a bunch of
using
statements to forward the API, you would enable a JSON pointer with a richer API, such asThe use case
My use-case is that I would like to iterate over all the leafs (number, boolean, null, strings) of a nested JSON data structure..
In order to do so, I would keep a vector of strings for the current position to which new elements are pushed back when meeting an array or object, and popped when leaving a level.
If this "key" is a JSON pointer, it could be used for access later, while right now, I would need to compose a string from it and pass it to the constructor of
json_pointer
, which is not very efficient.The text was updated successfully, but these errors were encountered: