✅ How can I filter for only JSON ModelState errors?
Hi,
I want to use Model State to return a custom failure response when invalid JSON is provided (for the request body, for example). The issue is, I am not sure what the best way to do this is because the errors messages do not have an associated exception with them.
What can I do so that my filter can successfully only return early on JSON errors?
If it helps, I am using the Newtonsoft JSON package.
Thanks for any help!



5 Replies
What does asp.net do by default for malformed JSON?
I'm not quite sure if this is the correct answer, but I think it uses the ModelState and automatically returns the ModelState response if SuppressModelStateInvalidFilter is false.
I have
SuppressModelStateInvalidFilter set to true so I can use a custom response format with an action filter.Why do you want a custom message though? What about the default is unsuitable?
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
I just wanted to stick with my custom message format which I am using for all API responses
I see
I’ll just leave it then, thanks