Is there any PHP library that validates a JSON object against a JSON Schema?
-
Implementations for various languages (and different libraries per language) are listed here: http://json-schema.org/ – hakre Sep 26 '12 at 12:29
5 Answers
I'm using Justin Rainbow's JSON Schema for PHP https://github.com/justinrainbow/json-schema and I'm quite happy about it.
It's a fork of http://jsonschemaphpv.sourceforge.net/
You can easily install it via Composer.

- 864
- 10
- 13
Take a look at http://json-schema.org/implementations.html . It has some validators in php and other languages.

- 1,767
- 3
- 16
- 21
About jsonschemaphpv, although it´s not very well maintained, we use it a lot and it works. It´s a port from the js validator. It has a full test suite that runs against the php and the http://code.google.com/p/jsonschema/.
And guess what... It passes on more tests than the js. At least at the last time I run the tests. The thing is that the project is not very well structured and looks ugly. But I ensure you it´s very stable. It also allows you to validate associative arrays as objects either.
I´ve written the tests in selenium first. After that I wrote them in phpunit. I´m not sure if the phpunit tests are there.
If you give it a try and really want to use it I can start a branch for it on github with the phpunit tests.
Bruno Reis (the person who ported the js to php)

- 66
- 1
-
It appears the code is hosted on SourceForge: http://sourceforge.net/projects/jsonschemaphpv/ – Jess Telford Oct 07 '11 at 00:33
-
2There is also a [GitHub](https://github.com/jesstelford/jsonschemaphp) repo. – Jess Telford Oct 07 '11 at 00:47
-
3Just to bring this up-to-date, the SourceForge repo for jsonschemaphpv seems to be outdated; but has been forked to Github here: https://github.com/justinrainbow/json-schema – haz Apr 26 '18 at 23:12
On the JSON Schema website there is a list of the implementions, amongst other things of validators in/for PHP:
jsv4-php - supports version 4 (Public Domain / MIT)
php-json-schema (MIT)
json-schema (Berkeley)
jvalidator (BSD3)
You could validate not JSON, but PHP array that could be obtained from many sources (JSON, XML, Post Data). To check if your array matches pattern you could take a look at https://github.com/ptrofimov/matchmaker

- 31
- 2