views:

383

answers:

2

Is there any PHP library that validates a JSON object against a JSON Schema?

A: 

I haven't used it but jsonschemaphpv might be a starting point.

salathe
Thanks, but there doesn't seem to be any release download there (unless you get the files out of SVN), and the project doesn't seem to be very active.
Omer
Like I said, a starting point. Hopefully someone else will come along with a full-featured, supported, battle-tested validator if one exists. :)
salathe
+1  A: 

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)

Bruno Reis