Request.get_json(), (or a new function), should return some sort of error message if the force parameter is not used notifying the user that this method only functions if the mime type is application/json unless the force option is used.
parsed_json = request.get_json() # Currently returns None
parsed_json.get("key") # Errors out
Alternatively, current usage can look like this:
parsed_json = request.get_json() # None
key_value = parsed_json.get("key", None)
if key_value:
# do stuff
else:
# do other stuff
In most scenarios there would be a failure at some stage or some form of custom handling for the current None behavior. Given that the function expects that application/json is in use it seems reasonable to enforce that expectation at some level.
To be totally fair, this would be a breaking change to anyone relying on the current None behavior so it would also be great if some sort of get_json_strict() existed with similar functionality. The end goal here is to just have some default visibility around this particular behavior of get_json().
This would affect
Request.get_json(), (or a new function), should return some sort of error message if the
forceparameter is not used notifying the user that this method only functions if themimetype isapplication/jsonunless theforceoption is used.Alternatively, current usage can look like this:
In most scenarios there would be a failure at some stage or some form of custom handling for the current
Nonebehavior. Given that the function expects that application/json is in use it seems reasonable to enforce that expectation at some level.To be totally fair, this would be a breaking change to anyone relying on the current
Nonebehavior so it would also be great if some sort ofget_json_strict()existed with similar functionality. The end goal here is to just have some default visibility around this particular behavior ofget_json().This would affect
werkzeug/src/werkzeug/wrappers/request.py
Line 540 in 8292df2