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
- opensuse-leap 16.0: perl-JSON-Validator 5.150.0-bp160.1.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms