-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Accessing value with json pointer adds key if not existing #1600
Comments
I use code like this:
Quote from README.md:
|
So looks like "at" might be the solution. I'd rather not be throwing and catching in normal paths though - would be nice if count() worked with json pointer too, then I could do if(count(json_pointer) then at(json_pointer). |
I only try/catch around optional entries that might not be present, in which case I may provide my own default as shown. I don't try/catch with entries I expect to be there. If that happens, I let the exception propagate back up to the caller, as I consider that a parse error. YMMV. |
I believe yes, as
AFAIK, this is not such API. To avoid copying, your best bet is probably a similar solution mentioned by @brouer. Here is documentation of
That's very good point. Though I think adding an overload to |
I understand the issue. The implementation of JSON Pointers is a bit hairy. I agree that |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I added a |
Looks good to me, thank you very much :D |
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
|
When accessing a key using json pointer, if the key doesn't exist, it is added. Is this expected behaviour? If so, is there some alternative const accessor we can use? For now, we are working around this by copying the object.
Please describe the steps to reproduce the issue. Can you provide a small but working code example?
What is the expected behavior?
{
"something": {
"else": "me"
},
"xyz": null <-- didn't expect this to be added when accessing via json pointer
}
Key added.
MSVC + Win 10
GCC + CentOS 7
develop
branch?Yes
The text was updated successfully, but these errors were encountered: