<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    JSON::Validator - Validate data against a JSON schema

VERSION
    0.58

SYNOPSIS
      use JSON::Validator;
      my $validator = JSON::Validator-&gt;new;

      # Define a schema - http://json-schema.org/examples.html
      # You can also load schema from disk or web
      $validator-&gt;schema(
        {
          type       =&gt; "object",
          required   =&gt; ["firstName", "lastName"],
          properties =&gt; {
            firstName =&gt; {type =&gt; "string"},
            lastName  =&gt; {type =&gt; "string"},
            age       =&gt; {type =&gt; "integer", minimum =&gt; 0, description =&gt; "Age in years"}
          }
        }
      );

      # Validate your data
      @errors = $validator-&gt;validate({firstName =&gt; "Jan Henning", lastName =&gt; "Thorsen", age =&gt; -42});

      # Do something if any errors was found
      die "@errors" if @errors;

DESCRIPTION
    JSON::Validator is a class for validating data against JSON schemas. You
    might want to use this instead of JSON::Schema if you need to validate
    data against draft 4
    &lt;https://github.com/json-schema/json-schema/tree/master/draft-04&gt; of the
    specification.

    This module is currently EXPERIMENTAL. Hopefully nothing drastic will
    change, but it needs to fit together nicely with Swagger2 - Since this
    is a spin-off project.

  Supported schema formats
    JSON::Validator can load JSON schemas in multiple formats: Plain perl
    data structured (as shown in "SYNOPSIS") or files on disk/web in the
    JSON/YAML format. The JSON parsing is done using Mojo::JSON, while the
    YAML parsing is done with an optional modules which need to be installed
    manually. JSON::Validator will look for the YAML modules in this order:
    YAML::XS, YAML::Syck, YAML::Tiny, YAML. The order is set by which module
    that performs the best, so it might change in the future.

  Resources
    Here are some resources that are related to JSON schemas and validation:

    *   &lt;http://json-schema.org/documentation.html&gt;

    *   &lt;http://spacetelescope.github.io/understanding-json-schema/index.htm
        l&gt;

    *   &lt;http://jsonary.com/documentation/json-schema/&gt;

    *   &lt;https://github.com/json-schema/json-schema/&gt;

    *   Swagger2

ERROR OBJECT
  Overview
    The method "validate" and the function "validate_json" returns error
    objects when the input data violates the "schema". Each of the objects
    looks like this:

      bless {
        message =&gt; "Some description",
        path =&gt; "/json/path/to/node",
      }, "JSON::Validator::Error"

  Operators
    The error object overloads the following operators:

    *   bool

        Returns a true value.

    *   string

        Returns the "path" and "message" part as a string: "$path:
        $message".

  Special cases
    Have a look at the test suite
    &lt;https://github.com/jhthorsen/json-validator/tree/master/t&gt; for
    documented examples of the error cases. Especially look at "jv-allof.t",
    "jv-anyof.t" and "jv-oneof.t".

    The special cases for "allOf", "anyOf" and "oneOf" will contain the
    error messages from all the failing rules below. It can be a bit hard to
    read, so if the error message is long, then you might want to run a
    smaller test with "JSON_VALIDATOR_DEBUG=1".

    Example error object:

      bless {
        message =&gt; "[0] String is too long: 8/5. [1] Expected number - got string.",
        path =&gt; "/json/path/to/node",
      }, "JSON::Validator::Error"

    Note that these error messages are subject for change. Any suggestions
    are most welcome!

FUNCTIONS
  validate_json
      use JSON::Validator "validate_json";
      @errors = validate_json $data, $schema;

    This can be useful in web applications:

      @errors = validate_json $c-&gt;req-&gt;json, "data://main/spec.json";

    See also "validate" and "ERROR OBJECT" for more details.

ATTRIBUTES
  cache_dir
      $self = $self-&gt;cache_dir($path);
      $path = $self-&gt;cache_dir;

    Path to where downloaded spec files should be cached. Defaults to
    "JSON_VALIDATOR_CACHE_DIR" or the bundled spec files that are shipped
    with this distribution.

  formats
      $hash_ref = $self-&gt;formats;
      $self = $self-&gt;formats(\%hash);

    Holds a hash-ref, where the keys are supported JSON type "formats", and
    the values holds a code block which can validate a given format.

    Note! The modules mentioned below are optional.

    *   date-time

        An RFC3339 timestamp in UTC time. This is formatted as
        "YYYY-MM-DDThh:mm:ss.fffZ". The milliseconds portion (".fff") is
        optional

    *   email

        Validated against the RFC5322 spec.

    *   hostname

        Will be validated using Data::Validate::Domain if installed.

    *   ipv4

        Will be validated using Data::Validate::IP if installed or fall back
        to a plain IPv4 IP regex.

    *   ipv6

        Will be validated using Data::Validate::IP if installed.

    *   uri

        Validated against the RFC3986 spec.

  ua
      $ua = $self-&gt;ua;
      $self = $self-&gt;ua(Mojo::UserAgent-&gt;new);

    Holds a Mojo::UserAgent object, used by "schema" to load a JSON schema
    from remote location.

    Note that the default Mojo::UserAgent will detect proxy settings and
    have "max_redirects" in Mojo::UserAgent set to 3. (These settings are
    EXPERIMENTAL and might change without a warning)

METHODS
  coerce
      $self = $self-&gt;coerce(booleans =&gt; 1, numbers =&gt; 1, strings =&gt; 1);
      $self = $self-&gt;coerce(1) # enable all
      $hash = $self-&gt;coerce;

    Set the given type to coerce. Before enabling coercion this module is
    very strict when it comes to validating types. Example: The string "1"
    is not the same as the number 1, unless you have coercion enabled.

    WARNING! Enabling coercion might hide bugs in your api, which would have
    been detected if you were strict. For example JavaScript is very picky
    on a number being an actual number. This module tries it best to convert
    the data on the fly into the proper value, but this means that you unit
    tests might be ok, but the client side libraries (that care about types)
    might break.

    Loading a YAML document will enable "booleans" automatically. This
    feature is experimental, but was added since YAML has no real concept of
    booleans, such as Mojo::JSON or other JSON parsers.

    The coercion rules are EXPERIMENTAL and will be tighten/loosen if bugs
    are reported. See &lt;https://github.com/jhthorsen/json-validator/issues/8&gt;
    for more details.

  schema
      $self = $self-&gt;schema(\%schema);
      $self = $self-&gt;schema($url);
      $schema = $self-&gt;schema;

    Used to set a schema from either a data structure or a URL.

    $schema will be a Mojo::JSON::Pointer object when loaded, and "undef" by
    default.

    The $url can take many forms, but needs to point to a text file in the
    JSON or YAML format.

    *   http://... or https://...

        A web resource will be fetched using the Mojo::UserAgent, stored in
        "ua".

    *   data://Some::Module/file.name

        This version will use "data_section" in Mojo::Loader to load
        "file.name" from the module "Some::Module".

    *   /path/to/file

        An URL (without a recognized scheme) will be loaded from disk.

  singleton
      $self = $class-&gt;singleton;

    Returns the JSON::Validator object used by "validate_json".

  validate
      @errors = $self-&gt;validate($data);

    Validates $data against a given JSON "schema". @errors will contain
    validation error objects or be an empty list on success.

    See "ERROR OBJECT" for details.

COPYRIGHT AND LICENSE
    Copyright (C) 2014-2015, Jan Henning Thorsen

    This program is free software, you can redistribute it and/or modify it
    under the terms of the Artistic License version 2.0.

AUTHOR
    Jan Henning Thorsen - "jhthorsen@cpan.org"

</pre></body></html>