-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Support empty string for safe access operator Currently only an empty json string, i.e. a string in a string was supported: '""'
.
#629
Conversation
Currently only an empty json string, i.e. a string in a string was supported: `'""'`.
742a783
to
4f52999
Compare
What was the error you were seeing when indexing an empty string? |
match val.as_json_value()? { | ||
serde_json::Value::Array(val) => { | ||
let index = index.as_i32()?; | ||
let indexed_value = val.get(index as usize).unwrap_or(&serde_json::Value::Null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't for this PR, but should we be throwing an error here? It doesn't seem like we'd want to silently ignore out of bounds accesses
When I add the test to master I get:
|
I'm not sure if this is actually desirable behavior, as empty strings will be valid values in many situations -- having a differentiation between empty strings and null does seem quite useful. However, I guess it also depends on how empty strings are treated elsewhere, which to be honest, I'm not 100% sure at this point -- and it miiiiiight be useful to then provide some easier way to convert empty strings into null... easier than |
yes, but the only situation where behavior wouldn't be unambiguous would be |
I think we should only make an empty string If you use a |
That i'd be more fine with, sure! Although this behavior should probably be documented very well |
Co-authored-by: Roland Fredenhagen <[email protected]>
Co-authored-by: Roland Fredenhagen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've adopted this pr in #1176 (i want to finally get this merged), this pr can therefore be closed.
thank you for your work!
Co-authored-by: Roland Fredenhagen <[email protected]>
Co-authored-by: Roland Fredenhagen <[email protected]>
Co-authored-by: Roland Fredenhagen <[email protected]>
Co-authored-by: Roland Fredenhagen <[email protected]>
* chore: apply pr #629 Co-authored-by: Roland Fredenhagen <[email protected]> * style: early return * feat: err on empty json string * docs: update docs * test: update test in accordance with decision * chore: attribution * docs: improve wording * docs: add breaking change notice to changelog * fix(changelog): fix pr link --------- Co-authored-by: Roland Fredenhagen <[email protected]>
Closing, as this has been merged as part of #1176. Thanks a ton for your work! |
Please follow this template, if applicable.
Description
Fixes
?.
for empty stringsUsage
{""?.test == "null"}
Additional Notes
TBD: should a json string i.e.
'""'
be considerednull
?Checklist
Please make sure you can check all the boxes that apply to this PR.
cargo fmt
to automatically format all code before committing