NAME
JSON::Schema::Fit - adjust data structure according to json-schema
VERSION
version 0.01
SYNOPSIS
my $data = get_dirty_result();
# raw data: got { num => "1.99999999997", flag => "1", junk => {...} }
my $bad_json = encode_json $data;
# {"num":"1.99999999997","flag":"1","junk":{...}}
# JSON::Schema-compatible
my $schema = { type => 'object', additionalProperties => 0, properties => {
num => { type => 'integer' },
flag => { type => 'boolean' },
}};
my $prepared_data = JSON::Schema::Fit->new()->get_adjusted($data, $schema);
my $cool_json = encode_json $prepared_data;
# {"num":2,"flag":true}
DESCRIPTION
The main goal of this package is preparing data to be encoded as json according to schema.
Actions implemented: adjusting value type (number/string/boolean), rounding numbers, filtering hash keys.
ATTRIBUTES
booleans
Explicitly set type for boolean values to JSON::true / JSON::false
Default: 1
numbers
Explicitly set type for numeric and integer values
Default: 1
round_numbers
Round numbers according to 'multipleOf' schema value
Default: 1
strings
Explicitly set type for strings
Default: 1
hash_keys
Filter out not allowed hash keys (where additionalProperties is false).
Default: 1
METHODS
get_adjusted
Returns "semi-copy" of data structure with adjusted values. Original data is not affected.
SEE ALSO
Related modules: JSON, JSON::Schema.
Json-schema home: http://json-schema.org/
AUTHOR
liosha <liosha@yandex-tean.ru>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by liosha.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.