NAME
Types::JSONSchema::PrimativeTypes - primative types supported by JSON
SYNOPSIS
use Types::JSONSchema::PrimativeTypes -all;
assert_JNumber( 55.5 );
assert_JBoolean( \1 );
assert_JObject( [] ); # dies
DESCRIPTION
This is a Type::Library exporting Type::Tiny type constraints.
Types
Primative Types
Note that the primative types are disjoint. Any given value can only satisfy at most one of them. The string "1" is a JString, but not a JBoolean or a JNumber.
- JNull
-
Accepts undef only.
- JBoolean
-
Accepts
builtin::true
,builtin::false
, and instances of boolean, JSON::PP::Boolean, or JSON::XS::Boolean. Also accepts\0
and\1
which are supposed to be interpreted as false and true respectively, though Perl will interpret\0
as true, makingis_JTrue
andis_JFalse
useful! - JNumber
-
Any valid number. This type does differentiate between "1" and 1 using the
created_as_number
andcreated_as_string
functions from builtin. - JString
-
Accepts any string. This type does differentiate between "1" and 1 using the
created_as_number
andcreated_as_string
functions from builtin. - JArray
-
Accepts any unblessed arrayref.
- JObject
-
Accepts any unblessed hashref.
Derived Types
- JTrue
-
Subtype of JBoolean for true values only. Accepts the following values:
boolean::true
,JSON::PP::true
,JSON::XS::true
,builtin::true
(or!!1
which is the same thing), and\1
.if is_JTrue($value)
is safer thanif $value
because it will recognize\0
as being false. - JFalse
-
Subtype of JBoolean for false values only. Accepts the following values:
boolean::false
,JSON::PP::false
,JSON::XS::false
,builtin::false
(or!!0
which is the same thing), and\0
(which Perl would normally interpret as being true!).if is_JFalse($value)
is safer thanif !$value
because it will recognize\0
as being false. - JInteger
-
Any JNumber with no fractional part. 1 and 1.000 are both considered integers.
- JAny
-
The union of all primative types.
Internal Types
- JSPrimativeName
-
Mostly for internal use. Accepts the literal strings "null", "boolean", "number", "string", "array", and "object".
- JSPrimativeType
-
Mostly for internal use. Accepts a blessed Type::Tiny object corresponding to one of the six primative types. Has a coercion from JSPrimativeName and also coerces "integer" to JInteger.
BUGS
Please report any bugs to https://github.com/tobyink/p5-types-jsonschema/issues.
SEE ALSO
AUTHOR
Toby Inkster <tobyink@cpan.org>.
COPYRIGHT AND LICENCE
This software is copyright (c) 2025 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.