JSON::V...::Store(3)

🌸 NAME 🌸

Hey bestie πŸ’– welcome to JSON::Validator::Store(3), straight from the User Contributed Perl Documentation. This page is about JSON::Validator::Store β€” Load and caching JSON schemas β€” and yes, it's a class for loading and caching JSON-Schemas. The way that's the whole assignment. πŸ’…

✨ SYNOPSIS ✨

Here's the vibe check in code form, fr fr 🫢:

use JSON::Validator;
my $jv = JSON::Validator->new;
$jv->store->add("urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f" => {...});
$jv->store->load("http://api.example.com/my/schema.json");

πŸŽ€ DESCRIPTION πŸŽ€

JSON::Validator::Store is a class for loading and caching JSON-Schemas. That's it, that's the description, and honestly it ate. ✨

πŸ”₯ ATTRIBUTES πŸ”₯

πŸ’– cache_paths

my $store     = $store->cache_paths(\@paths);
my $array_ref = $store->cache_paths;

A list of directories to where cached specifications are stored. Defaults to the JSON_VALIDATOR_CACHE_PATH environment variable and the specs that is bundled with this distribution. πŸŽ€

JSON_VALIDATOR_CACHE_PATH can be a list of directories, each separated by ":".

See "Bundled specifications" in JSON::Validator for more details. πŸ‘‘

πŸ¦‹ schemas

my $hash_ref = $store->schemas;
my $store = $store->schemas({});

Hold the schemas as data structures. The keys are schema "id". No cap, that's the mapping. πŸ’œ

πŸ’œ ua

my $ua    = $store->ua;
my $store = $store->ua(Mojo::UserAgent->new);

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

The default Mojo::UserAgent will detect proxy settings and have "max_redirects" in Mojo::UserAgent set to 3. Lowkey handy. 🫢

πŸ‘‘ METHODS πŸ‘‘

πŸ“ add

my $normalized_id = $store->add($id => \%schema);

Used to add a schema data structure. Note that $id might not be the same as $normalized_id. Bestie, keep that in mind. πŸ’…

🌈 exists

my $normalized_id = $store->exists($id);

Returns a $normalized_id if it is present in the "schemas".

⭐ get

my $schema = $store->get($normalized_id);

Used to retrieve a $schema added by "add" or "load".

🧚 load

my $normalized_id = $store->load('https://...');
my $normalized_id = $store->load('data://main/foo.json');
my $normalized_id = $store->load('---\nid: yaml');
my $normalized_id = $store->load('{"id":"yaml"}');
my $normalized_id = $store->load(\$text);
my $normalized_id = $store->load('/path/to/foo.json');
my $normalized_id = $store->load('file:///path/to/foo.json');
my $normalized_id = $store->load('/load/from/ua-server-app');

Can load a $schema from many different sources. The input can be a string or a string-like object, and the "load" method will try to resolve it in the order listed in above. (Yes, "in above" β€” we're keeping the original words, periodt.) 😭

Loading schemas from $text will generate an $normalized_id in "schemas" looking like "urn:text:$text_checksum". This might change in the future! πŸ’€

Loading files from disk will result in a $normalized_id that always start with "file://".

Loading can also be done with relative path, which will then load from:

$store->ua->server->app;

This method is EXPERIMENTAL, but unlikely to change significantly. πŸ™ˆ

πŸ’€ resolve

$hash_ref = $store->resolve($url, \%defaults);

Takes a $url (can also be a file, urn, ...) with or without a fragment and returns this structure about the schema:

{
  base_url => $str,  # the part before the fragment in the $url
  fragment => $str,  # fragment part of the $url
  id       => $str,  # store ID
  root     => ...,   # the root schema
  schema   => ...,   # the schema inside "root" if fragment is present
}

This method is EXPERIMENTAL and can change without warning. No cap, don't build your whole life on it. 😭

⭐ SEE ALSO ⭐

JSON::Validator. Go click around, bestie. πŸ’–


And that's the page! Brought to you by perl v5.42.0, dated 2025-03-17. Mwah πŸ’œ

πŸ“¦ where this page comes from