Quantcast
Channel: PHPDeveloper.org
Viewing all articles
Browse latest Browse all 15

Rob Allen: Validating JSON with ZF2's ZendValidator

0
0

Rob Allen has a quick post today showing how to use the ZendValidator component from Zend Framework 2 to handle JSON validation.

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.

He starts with a quick example of using the "JsonParser" in isolation to validate a JSON string. Then he integrates it into the framework as a custom validator class (extending the AbstractValidator) and enabling the "isValid" call to be made and return a pass/fail result. You can find out more about the ZendValidator component in this page of the Zend Framework manual.

Link: http://akrabat.com/zend-framework-2/validating-json-with-zf2s-zendvalidator/

Viewing all articles
Browse latest Browse all 15

Latest Images

Trending Articles





Latest Images