version 0.85
=head1 SYNOPSIS
# In your tidyall config
[GenericValidator / JSONOrderedTidy]
cmd = json-ordered-tidy
argv = -check
ok_exit_codes = 0 1
=head1 DESCRIPTION
This pl
hift;
return unless $self->_has_options;
my $conf_file = $self->_tempdir->child('jshint.json');
$conf_file->spew(
'{ ' . join( ",\n", map {qq["$_": true]} split /\s+/, $self->opt
ef
; or refer to a jshint.json config file in the same directory
;
[JSHint]
select = static/**/*.js
argv = --config $ROOT/jshint.json
where jshint.json looks like
{
"bitw
EXPORT = qw|
resInit resHeader resCookie resBuffer resFd resStatus resRedirect
resNotFound resJSON resBinary resFile resFinish
|;
# try to load PerlIO::gzip, resBuffer will check for its availab
lf);
}
my $_json_codec;
sub resJSON {
my($self, $obj) = @_;
$_json_codec ||= TUWF::Misc::_JSON()->new->convert_blessed->utf8;
$self->resHeader('Content-Type' => 'application/json; charset=UTF
-8');
$self->resBinary($_json_codec->encode($obj), 'clear');
}
sub resBinary {
my($self, $data, $buffer) = @_;
my $enc = $self->resBuffer($buffer//'none', 'noutf8');
if($enc eq 'none') {
);
use Cpanel::JSON::XS;
use File::Slurper qw (read_text);
use File::Spec;
use Readonly;
use Data::Walk;
use Try::Tiny;
our $VERSION = 0.10;
our $override;
my $JSON_OBJ = Cpanel::JSON::XS->new()->ut
fixtures);
$self->_set_mock_dbh($fixtures);
} elsif (-e $self->{fixture_file}) {
my $data = $JSON_OBJ->decode(read_text($self->{fixture_file}));
$self->_process_mock_data($data);
$self->_set_
($directory . $FIXTURE_DIR);
my $default_fixture_file = $directory . $FIXTURE_DIR . "$test_file.json";
$self->{fixture_file} = $default_fixture_file;
}
return $self;
}
sub _validate_args {
my
d2 reqJSON()
Returns the decoded JSON object if the request body was of type
C<application/json>; Returns C<undef> otherwise.
This requires either the L<JSON::XS>, L<Cpanel::JSON::XS> or L<JSON::PP>
module. If none of these modules is not available, any request with a JSON body
will automatically get a 500 response.
=head2 reqUploadMIMEs(name)
When I<name> is not given, returns a list of all p
ersion 0.85
=head1 SYNOPSIS
# In your tidyall config
[GenericTransformer / JSONOrderedTidy]
cmd = json-ordered-tidy
argv = -stdout
ok_exit_codes = 0 1
=head1 DESCRIPTION
This p
nd cookies set before calling C<resRedirect()>.
=head2 resJSON(data)
Sets the content type to C<application/json> and sends the encoded JSON object
to the client.
=head2 resBinary(data, buffer_acti
mples|lib|inc|t|xt|maint)/|(?:(?:Makefile|Build)\.PL|README|LICENSE|MANIFEST|Changes|META\.(?:yml|json))$)
# Avoid version control files.
\bRCS\b
\bCVS\b
,v$
\B\.svn\b
\b_darcs\b
# (.git or .hg only
# Error objects should be plain data structures so that they can easily
# be converted to JSON for debugging. We have to stringify $reg in the
# error object to ensure that.
+{ type =>
0] = $_[0] ? 1 : 0; 1 } },
jsonbool => { type => 'any', func => sub {
my $r = $_[0];
blessed $r && (
$r->isa('JSON::PP::Boolean')
|| $r->isa('JSON::XS::Boolean')
|| $r-
|| $r->isa('Cpanel::JSON::XS::Boolean')
|| $r->isa('boolean')
) ? 1 : {};
} },
# JSON number format, regex from http://stackoverflow.com/questions/13340717/json-numbers-regular-expre
rgument Source
post reqPosts()
get reqGets()
param reqParams()
json reqJSON()
This method takes several different forms for the further arguments (the
examples below
re schema will be compiled with the
L<custom_validations|TUWF/custom_validations> setting.
The C<json> source only supports the I<Hash value> form. Using the C<param>
source is discouraged, as it is
ype => 'array', scalar => 1} >> schema.
Some examples:
# JSON, with custom error handling
my $validation_result = tuwf->validate(json => {
type => 'hash',
keys => {
username => { l
> $_[1]{max};
return 1;
}
my %default_templates = (
# JSON number format, regex from http://stackoverflow.com/questions/13340717/json-numbers-regular-expression
num => { func => \&_templat
{
my $self = shift;
my $what = shift;
return _compile($_[0])->validate($self->reqJSON) if $what eq 'json';
# 'param' is special, and not really encouraged. Create a new hash based on
# re
riate JSON
# module. Kinda like JSON::MaybeXS, but without an extra dependency.
sub _JSON {
return 'JSON::XS' if $INC{'JSON/XS.pm'};
return 'Cpanel::JSON::XS' if $INC{'Cpanel/JSON/XS.p
ERSION = '1.6';
our @EXPORT = qw|
reqInit reqGets reqGet reqPosts reqPost reqParams reqParam reqJSON
reqUploadMIMEs reqUploadMIME reqUploadRaws reqUploadRaw reqSaveUpload
reqCookie reqMethod req
YPE'}||'') =~ m{^application/json(?:;.*)?$}) {
$self->{_TUWF}{Req}{JSON} = _parse_json($data);
die TUWF::Exception->new('json') if !$self->{_TUWF}{Req}{JSON};
} elsif(($RENV->{'C
}, $val;
}
return \%dat;
}
my $_json_codec;
sub _parse_json {
my $d = shift;
$_json_codec ||= TUWF::Misc::_JSON()->new->utf8;
my $res = eval { $_json_codec->decode($d) };
return undef i
a of
truth.
=item jsonbool => 1
Require the input to be a boolean type returned by a JSON parser. Supported
types are L<JSON::PP>, L<JSON::XS>, L<Types::Serialiser>, L<Cpanel::JSON::XS>
and L<boolea
C<< type => 'scalar' >>. Require the input to be a number formatted
using the format permitted by JSON. Note that this is slightly more restrictive
from Perl's number formatting, in that 'NaN', 'Inf'
it faster than
TUWF::Validate, at the cost of higher memory usage and a large dependency tree.
L<JSON::Schema> is similar to Sah: It features more advanced data structure
validation, but the schema i
t' || $n eq 'uint';
$o->{type} = 'bool' if $n eq 'anybool' || $n eq 'undefbool' || $n eq 'jsonbool';
$o->{type} = 'num' if $n eq 'num';
}
sub _merge {
my($c, $o) = @_;
_merge_type
odd things may
# happen if this is not the case.
# unknown => remove|reject|pass
sub coerce_for_json {
my($o, $obj, %opt) = @_;
$opt{unknown} ||= $o->{unknown};
return undef if !defined $obj;
o->{values}->coerce_for_json($_, %opt), @$obj] if $o->{type} eq 'array' && $o->{values};
return {map {
$o->{keys}{$_} ? ($_, $o->{keys}{$_}->coerce_for_json($obj->{$_}, %opt)) :
CONTRIBUTING.pod')->spew_raw($content);
path($config->{build_root}, 'META.json')->copy(path($config->{root}, 'META.json'));
}
=head1 DESCRIPTION
This role is for C<Dist::Zilla> C<Plugin>'s tha
la>
=item * Copy files from the build tree
path($config->{build_root}, "META.json")->copy($path->{root}, "META.json");
( Note: This case is implemented by L<< C<[Regenerate]>|Dist::Zilla::Plugin:
jpeg image/jpeg
jpg image/jpeg
js application/javascript
json application/json
jxl image/jxl
mjs application/javascript
mp3 audio/mpeg
ontrolchar';
warn "Client sent an invalid JSON object. Generating HTTP 400 response.\n" if $terr eq 'json';
my $han = {
utf8 => 400,
json => 400,
controlchar => 400,
ader($_)), $self->reqHeader).
"POST dump:\n".
($self->reqJSON()
? TUWF::Misc::_JSON()->new->pretty->encode($self->reqJSON())
: join('', map sprintf(" %s: %s\n", $_, join "\n ",
ommon;
requires qw(
json
);
has url => (
is => 'ro',
isa => 'Str',
predicate => 'has_url',
);
sub generate_json_body {
my ( $self, %args ) = @_;
return $self->json->encode({ %args });
}
/json; charset=utf-8' )
];
my $request = Langertha::Request::HTTP->new(
http => [ uc($method), $uri, $headers, ( scalar %args > 0 ?
( !$content_type or $content_type eq 'application/json
' )
? $self->generate_json_body(%args)
: ()
: ()
) ],
request_source => $self,
response_call => $response_call,
);
if ($content_type and $content_type eq 'multi
rl
# ABSTRACT: JSON grammar test
$|=1;
use FindBin;
use lib "$FindBin::Bin/../lib";
use utf8;
use open ':std', ':encoding(UTF-8)';
use strict;
use warnings;
use Data::Dumper;
use JSON::MaybeXS;
use
s $ENV{OLLAMA_URL};
my $model = $ENV{OLLAMA_MODEL} || 'gemma2:2b';
my $jsonschema = <<'__EOS__';
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
s JSON, and your JSON always follows this specific JSON Schema:
$jsonschema
__EOP__
{
my $start = time;
my $ollamajson = Langertha::Engine::Ollama->new(
url => $ENV{OLLAMA_URL},
json_f
rp qw( croak );
use JSON::MaybeXS ();
use JSON::PP ();
use OpenAPI::Modern;
use Path::Tiny;
use URI;
use YAML::PP;
requires qw(
openapi_file
generate_http_request
url
json
);
has openapi =>
n OpenAPI::Modern->new(
openapi_uri => $yaml,
openapi_schema => YAML::PP->new(boolean => 'JSON::PP')->load_string(path($yaml)->slurp_utf8),
);
}
has supported_operations => (
is => 'ro',
->{requestBody}->{content} )
? $operation->{requestBody}->{content}->{'application/json'} ? 'application/json'
: $operation->{requestBody}->{content}->{'multipart/form-data'} ? 'multipart/fo
e Text::Trim qw(trim);
use Syntax::Keyword::Try;
use XML::Fast;
use Locale::Country;
use JSON qw(to_json);
use Digest::SHA qw(sha256_hex);
use Encode qw(encode);
use constant MAX_REDIRECT
a);
=cut
sub _create_hash {
my ($data) = @_;
# Convert the data to a JSON string
my $json_string = to_json(
$data,
{
canonical => 1,
utf8 =>
1
});
# Generate and return the SHA-256 hash
return sha256_hex($json_string);
}
1;