in reply to How to validate json with json-schema draft 4?

I need to validate json files with json-schama in perl script. But unfortunately perl module JSON::Schema does not support the current version of json schema.

Cool, an opportunity to fix/improve something

Is there any way of validation json with json-schema draft 4 in perl?

Yes, SMOP :D

I have created a sample repo that shows the problem: https://github.com/bessarabov/playing_with_json_schema/

Ah yes, code on github, that uses "doker" that depends on npm ... the perfect and most simple and self contained way to demonstrate a problem ... directest way possible to ask perlmonks for help

http://search.cpan.org/grep?cpanid=TOBYINK&release=JSON-Schema-0.016&string=required&i=1&n=1&C=0

https://metacpan.org/source/TOBYINK/JSON-Schema-0.016/t/03required.t

#!/usr/bin/perl -- use strict; use warnings; use JSON::Schema; use JSON::Hyper; use JSON; use Data::Dump qw/ dd /; #~ http://cpansearch.perl.org/src/TOBYINK/JSON-Schema-0.016/examples/v +alidation.pl $JSON::Hyper::DEBUG = 1; my $schema = q{{ "properties" : { "name" : { "type" : "string" }, "type" : { "enum" : [ "dog", "cat" ], "type" : "string" } }, "required" : [ "name", "type" ], "type" : "object" }}; my $data = q{{ "nickname" : "Buddy", "type" : "dog" }}; ## hack my $validator = JSON::Schema->new( $schema ); for my $prop ( @{ $validator->{schema}{required} } ){ $validator->{schema}{properties}{$prop}{required}++; } my $json = decode_json( $data ); my $result = $validator->validate( $json ); dd( $validator, $json, $result ); print "$_\n" foreach $result->errors; ## wanted #~ [ { keyword: 'required', #~ dataPath: '', #~ params: { missingProperty: 'name' }, #~ message: 'should have required property \'name\'' } ] #~ #~ #~ __END__ ( bless({ format => {}, schema => { properties => { name => { required => 1, type => "string" }, type => { enum => ["dog", "cat"], required => 1, typ +e => "string" }, }, required => ["name", "type"], type => "object", }, }, "JSON::Schema"), { nickname => "Buddy", type => "dog" }, bless({ errors => [ { message => "is missing and it is required", property + => "\$.name" }, ], valid => "", }, "JSON::Schema::Result"), ) $.name: is missing and it is required