GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
JSON::Validator::Util(3) User Contributed Perl Documentation JSON::Validator::Util(3)

JSON::Validator::Util - Utility functions for JSON::Validator

JSON::Validator::Util is a package containing utility functions for JSON::Validator. Each of the "FUNCTIONS" can be imported.

  $str = data_checksum $any;

Will create a checksum for any data structure stored in $any.

  $str = data_section "Some::Module", "file.json";
  $str = data_section "Some::Module", "file.json", {encode => 'UTF-8'};

Same as "data_section" in Mojo::Loader, but will also look up the file in any inherited class.

  $str = data_type $any;
  $str = data_type $any, [@schemas];
  $str = data_type $any, [{type => "integer", ...}];

Returns the JSON type for $any. $str can be array, boolean, integer, null, number object or string. Note that a list of schemas need to be provided to differentiate between "integer" and "number".

  $bool = is_bool $any;

Checks if $any looks like a boolean.

  $bool = is_num $any;

Checks if $any looks like a number.

  $bool = is_type $any, $class;
  $bool = is_type $any, $type;

Checks if $any is a, or inherits from, $class or $type.

  $content_type = negotiate_content_type($header, \@content_types);

This method can take a "Content-Type" or "Accept" header and find the closest matching content type in @content_types. @content_types can contain wildcards, meaning "*/*" will match anything.

  @errors = prefix_errors $prefix, @errors;

Consider this internal for now.

  $str = schema_type $hash_ref;
  $str = schema_type $hash_ref, $any;

Looks at $hash_ref and tries to figure out what kind of type the schema represents. $str can be "array", "const", "number", "object", "string", or fallback to empty string if the correct type could not be figured out.

$any can be provided to double check the type, so if $hash_ref describes an "object", but $any is an array-ref, then $str will become an empty string. Example:

  # $str = "";
  $str = schema {additionalProperties => false}, [];

  # $str = "object"
  $str = schema {additionalProperties => false};
  $str = schema {additionalProperties => false}, {};

Note that this process is relatively slow, so it will make your validation faster if you specify "type". Both of the two below is valid, but the one with "type" will be faster.

  {"type": "object", "properties": {}} # Faster
  {"properties": {}}                   # Slower

  $any = str2data $str;

Will try to parse $str as JSON or YAML, and return a data structure.

JSON::Validator.
2021-10-02 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.