Replies: 1 comment
-
Have you looked at the JSON Pointer support? I haven't used it myself, but it looks like this does what you want:
https://github.com/nlohmann/json/blob/master/doc/examples/basic_json__value_ptr.cpp |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I use this library quite extensively inside a large project, and I found that I normally require to access to nested paths of an object, where many times the value is missing, or the content is not what expected. Doing that with the current library can be complicated and iterative, so I ended up doing a small function to look for a key in a path and return it, or return a default value if not found, not of the same type, etc.
The code is the following:
I use like that:
And it saves a lot of code checking for json root type, nested objects, value type, etc. It is a first attempt and for sure it can be improved a lot, but just wanted to share if someone find it useful, or something similar can be included in the library.
Thanks! Regards.
Beta Was this translation helpful? Give feedback.
All reactions