JSON::V...or::Util(3)

πŸŽ€ NAME πŸŽ€ β€” JSON::V...or::Util(3)

okay bestie, you're reading the User Contributed Perl Documentation for JSON::V...or::Util(3) πŸ’–. The module in question is JSON::Validator::Util β€” literally "Utility functions for JSON::Validator". That's the whole NAME moment, and it ate. πŸ’…

🌸 DESCRIPTION 🌸

JSON::Validator::Util is a package that's lowkey just utility functions for JSON::Validator. Each of the "FUNCTIONS" can be imported. slay. ✨

πŸ¦‹ FUNCTIONS πŸ¦‹

πŸ“ data_checksum

$str = data_checksum $any;

Will create a checksum for any data structure stored in $any. it's giving data fingerprint realness. πŸ”₯

πŸ“ data_section

$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. inherited-class detective work, iconic. πŸ•΅οΈβ€β™€οΈ

πŸ“ data_type

$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". no cap, that distinction matters. πŸ’―

πŸ“ is_bool

$bool = is_bool $any;

Checks if $any looks like a boolean. vibe check for booleans. πŸ¦‹

πŸ“ is_num

$bool = is_num $any;

Checks if $any looks like a number. math girlie check. πŸ”’

πŸ“ is_type

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

Checks if $any is a, or inherits from, $class or $type. it's giving ancestry.com for Perl classes. 🌈

πŸ“ negotiate_content_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. wildcard slay. ✨

πŸ“ prefix_errors

@errors = prefix_errors $prefix, @errors;

Consider this internal for now. bestie, it's giving "do not touch unless you know what you're doing" energy. πŸ™ˆ

πŸ“ schema_type

$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. detective mode. πŸ”

$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

πŸ“ str2data

$any = str2data $str;

Will try to parse $str as JSON or YAML, and return a data structure. parsing queen. πŸ‘‘

πŸ’œ SEE ALSO πŸ’œ

JSON::Validator.

kisses 😘 this was brought to you by perl v5.42.0, dated 2025-03-17, and yes the page is JSON::V...or::Util(3) β€” bye bestie, go validate something cute πŸ’…

πŸ“¦ where this page comes from