1JSON::Validator::Util(3U)ser Contributed Perl DocumentatiJoSnON::Validator::Util(3)
2
3
4

NAME

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

DESCRIPTION

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

FUNCTIONS

13   data_checksum
14         $str = data_checksum $any;
15
16       Will create a checksum for any data structure stored in $any.
17
18   data_section
19         $str = data_section "Some::Module", "file.json";
20         $str = data_section "Some::Module", "file.json", {encode => 'UTF-8'};
21
22       Same as "data_section" in Mojo::Loader, but will also look up the file
23       in any inherited class.
24
25   data_type
26         $str = data_type $any;
27         $str = data_type $any, [@schemas];
28         $str = data_type $any, [{type => "integer", ...}];
29
30       Returns the JSON type for $any. $str can be array, boolean, integer,
31       null, number object or string. Note that a list of schemas need to be
32       provided to differentiate between "integer" and "number".
33
34   is_bool
35         $bool = is_bool $any;
36
37       Checks if $any looks like a boolean.
38
39   is_num
40         $bool = is_num $any;
41
42       Checks if $any looks like a number.
43
44   is_type
45         $bool = is_type $any, $class;
46         $bool = is_type $any, $type;
47
48       Checks if $any is a, or inherits from, $class or $type.
49
50   negotiate_content_type
51         $content_type = negotiate_content_type($header, \@content_types);
52
53       This method can take a "Content-Type" or "Accept" header and find the
54       closest matching content type in @content_types. @content_types can
55       contain wildcards, meaning "*/*" will match anything.
56
57   prefix_errors
58         @errors = prefix_errors $prefix, @errors;
59
60       Consider this internal for now.
61
62   schema_type
63         $str = schema_type $hash_ref;
64         $str = schema_type $hash_ref, $any;
65
66       Looks at $hash_ref and tries to figure out what kind of type the schema
67       represents. $str can be "array", "const", "number", "object", "string",
68       or fallback to empty string if the correct type could not be figured
69       out.
70
71       $any can be provided to double check the type, so if $hash_ref
72       describes an "object", but $any is an array-ref, then $str will become
73       an empty string. Example:
74
75         # $str = "";
76         $str = schema {additionalProperties => false}, [];
77
78         # $str = "object"
79         $str = schema {additionalProperties => false};
80         $str = schema {additionalProperties => false}, {};
81
82       Note that this process is relatively slow, so it will make your
83       validation faster if you specify "type". Both of the two below is
84       valid, but the one with "type" will be faster.
85
86         {"type": "object", "properties": {}} # Faster
87         {"properties": {}}                   # Slower
88
89   str2data
90         $any = str2data $str;
91
92       Will try to parse $str as JSON or YAML, and return a data structure.
93

SEE ALSO

95       JSON::Validator.
96
97
98
99perl v5.36.0                      2023-01-20          JSON::Validator::Util(3)
Impressum