Developing software in the Real World

Validating JSON with ZF2's Zend\Validator

Let’s say that you have an admin form where the user can enter JSON and you’d like to validate that the JSON parses before allowing the user to submit. To do this, you can use the rather excellent jsonlint project by Jordi Boggiano. Obviously, add it via Compser :)

Usage is simple:

We can wrap this up into a Zend Framework 2 validator quite easily:

Simply add RKA\Validator\Json to the input filter of the element in question and we’re done.

One thought on “Validating JSON with ZF2's Zend\Validator

Comments are closed.