-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
JSON Api refuse to decode null value #27600
Comments
Yep, it doesn't work, and I don't think it ever will. The intent and use case behind the Zephyr JSON module isn't documented, but it appears to be designed to process nested non-empty structures. There's no provision for indicating that an object can be skipped. This is clear from the basic API:
A successful return value indicates that the JSON text provided what's necessary to set all fields of the If you need to process JSON that has more free-form content you'll need a different JSON support library. I've had very good experience in the past with jsmn, but it does require a buffer large enough to hold a record of all tokens provided. If that isn't usable I would consult the Google. I'm converting this to an enhancement as it isn't something that can be easily fixed. |
thx. @pabigot jsmn library works us expected. Dear @MaureenHelm thx. a lot and feel free to close this issue. Could you consider to add jsmn us alternative to current JSON Api? |
Null value in JSON {"key_null": null} would be ignored. Fixes zephyrproject-rtos#27600 Signed-off-by: Jackie Ja <[email protected]>
not sure why it was closed and something that can't be easily fixed does not makes it an enhancement either. Also, it seems with have a proposal for a fix. |
It was an enhancement because the json API wasn't designed to support missing content. If the input specified doesn't cover the entire structure, there's a potential security issue because whatever was left in that buffer could be misinterpreted. Looks like #28905 requires that the target object be pre-initialized with values that can be interpreted as "this isn't here". That may not be possible in general, especially when existing code relies on presence of all described data. So I don't think this is a bug, it's a design limitation that is not trivial to eliminate. |
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
Describe the bug
I am trying to use JSON API to decode json messages with json_obj_parse function. Everything was working fine until same of keys came with null values. json_obj_parse function always return with error code -22 (EINVAL).
I have checked null at json.org and jsonlint.com, looks like that null is valid json value.
Try to parse the simplest json possible, but with same result.
{ "key" : null }
Try to look at zephyr json test, there is comment actually describing this situation.
To Reproduce
Expected behavior
I expect JSON API to decode null values.
Impact
annoyance, showstopper
Logs and console output
Environment (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: