Is JSON validation a best practice?

user290 picture user290 · Nov 21, 2008 · Viewed 8.9k times · Source

Is it a best practice to validate JSON?

With both a JSON schema proposal and a JavaScript implementation of a JSON Schema validator, this practice would seem relatively frictionless to implement. So, is it a no-brainer that should be part of any robust application? Or do you employ other preferred strategies to handle bad JSON?

Answer

moonshadow picture moonshadow · Nov 21, 2008

On the server, validation of data coming from outside is a must.

In the browser, it is redundant from a security POV, if you can vouch that the JSON is generated by server code you control and that any data it depends on has been validated on the server. Even so it can still be useful for debugging.