NAME

JSON::TinyValidatorV4 - JSON Validator for v4 JSON Schema

SYNOPSIS

use JSON::TinyValidatorV4;
use Data::Dumper;

my $schema = {
    type       => 'object',
    properties => {
        latitude  => { type => 'number' },
        longitude => { type => 'number' }
    }
};

my $data = { longitude => -128.323746, latitude => -24.375870, elevation=> 23.1 };

my $tv4 = JSON::TinyValidatorV4->new;

print $tv4->validate( $data, $schema ), "\n";        # prints "1"
print $tv4->validate( $data, $schema, 0, 1 ), "\n";  # prints "0"

print Dumper( $tv4->validateResult( $data, $schema, 0, 1 ) );
# prints:
# $VAR1 = {
#           'valid' => 0,
#           'error' => {
#                      'message' => 'Unknown property (not in schema)',
#                      'dataPath' => '/elevation',
#                       ...
#                    },
#           'missing' => []
#         };

DESCRIPTION

This package is a wrapper for Tiny Validator. It uses json-schema draft v4 to validate simple values and complex objects. For details see also SEE ALSO.

validate( $data, $schema, [ $checkRecursive=0, $banUnknownProperties=0 ] )

validates $data with $schema. $checkRecursive and $banUnknownProperties are false by default. returns 0 or 1.

validateResult( $data, $schema, [ $checkRecursive=0, $banUnknownProperties=0 ] )

validates $data with $schema. $checkRecursive and $banUnknownProperties are false by default. returns an result hash:

{
    valid   => 0,
    error   => {...},
    missing => [...]
}

SEE ALSO

Tiny Validator at github: L<https://github.com/geraintluff/tv4>

AUTHORS

Michael Langner, mila at cpan dot org

THANKS

This package uses an embedded copy of Tiny Validator (https://github.com/geraintluff/tv4) to do all the validation work.

COPYRIGHT & LICENSE

Copyright 2015 Michael Langner, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.