Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at /home/mojo/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/JSON/Schema.pm line 48.
- #!/usr/bin/env perl
- use Mojolicious::Lite;
- use Mojo::JSON qw(decode_json encode_json);
- use JSON::Schema;
- use Mojo::UserAgent;
- get '/address' => sub {
- my $self = shift;
- my $ua = Mojo::UserAgent->new;
- my $schema = $ua->get('http://json-schema.org/card')->res->body;
- my $validator = JSON::Schema->new($schema);
- my $contact = encode_json {
- fn => 'Toby Inkster',
- nickname => 'TOBYINK',
- email => { value => 'tobyink@cpan.org' },
- adr => { countryName => 'England', region => 'East Sussex' },
- };
- my $valid = $validator->validate($contact);
- if ($valid) {
- $self->render(text => $contact, status => 200);
- exit;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement