|
NAMEJSON::Schema - validate JSON against a schemaSYNOPSISmy $validator = JSON::Schema->new($schema, %options); my $json = from_json( ... ); my $result = $validator->validate($json); if ($result) { print "Valid!\n"; } else { print "Errors\n"; print " - $_\n" foreach $result->errors; } STATUSThis module offers good support for JSON Schema as described by draft specifications circa 2012.However, since then the JSON Schema draft specifications have changed significantly. It is planned for this module to be updated to support the changes, however this work will not be undertaken until the JSON Schema specifications become more stable. (Being published as an IETF RFC will be seen as sufficient stability.) DESCRIPTIONConstructors
Methods
Perl SpecificsPerl uses weak typing. This module largely gives JSON instances the benefit of the doubt. For example, if something looks like a number (e.g. a string which only includes the digits 0 to 9) then it will validate against schemas that require a number.The module extends JSON Schema's native set of types ('string', 'number', 'integer', 'boolean', 'array', 'object', 'null', 'any') with any Perl package name. i.e. the following is valid: my $validator = JSON::Schema->new({ properties => { 'time' => { type => ['DateTime','string'] }, }, }); my $object = { 'time' => DateTime->now; }; my $result = $schema->validate($object); This extension makes JSON::Schema useful not just for validating JSON structures, but acyclic Perl structures generally. Acyclic. Yes, acyclic. You don't want an infinite loop. BUGSPlease report any bugs to <http://rt.cpan.org/>.SEE ALSOJSON::Schema::Result, JSON::Schema::Error, JSON::Schema::Helper, JSON::Schema::Null, JSON::Schema::Examples.Related modules: JSON::T, JSON::Path, JSON::GRDDL, JSON::Hyper. <http://tools.ietf.org/html/draft-zyp-json-schema>. AUTHORToby Inkster <tobyink@cpan.org>.This is largely a port of Kris Zyp's Javascript JSON Schema validator <http://code.google.com/p/jsonschema/>. COPYRIGHT AND LICENCECopyright 2007-2009 Kris Zyp.Copyright 2010-2012 Toby Inkster. This module is tri-licensed. It is available under the X11 (a.k.a. MIT) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. a.k.a. "The MIT Licence"Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Visit the GSP FreeBSD Man Page Interface. |