NAME

Jasonify - Just Another Serialized Object Notation library.

SYNOPSIS

use Jasonify;

my $jasonify = Jasonify->new( ... );    # See OPTIONS below
$jasonify = $jasonify->set( ... );      # See OPTIONS below
print $jasonify->encode( ... );         # ...

# Or

Jasonify->set( ... );                   # See OPTIONS below
print Jasonify->encode( ... );          # ...

DESCRIPTION

Jasonify is very similar to JSON, except that it's easier to use, has better defaults and options.

OPTIONS

Encode options

list_sep => ', '
beautify => undef

Undefify options

null => 'null'

How undef is encoded.

Booleanify options

false => 'false'
true => 'true'

How the boolean values are encoded.

Stringify options

quote => '"'

Use double-quoted strings in all cases.

longstr => -1

All strings are to be considered long, and encoded accordingly.

econde2 => { ... }
[[:cntrl:]] => sprintf( '\\u00%02x', ord($_) )
"\x{2028}", "\x{2029}" => sprintf( '\\u%04x', ord($_) )
"\b" => '\b'
"\t" => '\t'
"\n" => '\n'
"\r" => '\r'
'"' => '\"'
'\\' => '\\\\'
byte => '\\u00%02x'
utf => 16
wide => '\\u%04x'

Special characters, and how they are encoded.

Numify options

infinite => "Infinifty",
-infinite => "-Infinifty",
nonnumber => "NaN",

How to encode the values for infinity, negative infinity, and not-a-number.

Lvalueify options

lvalue => '$lvalue'

Encode lvalues as simple strings.

Vstringify options

vformat => '\\u%0*v4x'
vsep => '\\u'

Encode vstrings as a series of 4-character hex digits separated by '\u'.

Arraryify options

array_ref => '[$_]'

A reference to an ARRAY is encoded in this manner.

Hashify options

hash_ref => '{$_}'

A reference to a HASH is encoded in this manner.

pair => '$key : $value'

Pairs are encoded in this manner.

keysort => \&Datify::keysort

The function used to sort entries in a hash.

keyfilter => undef

How to filter items in a HASH.

keyfilterdefault => 1

How to interpret filtered items in a HASH.

Objectify options

json_method => 'TO_JSON'

The method to search for to see if an object has a specific representation for itself.

object => '$data'

Objects are decomposed using this. If you wanted to decompose objects with the class name in addition to the internal representation of the data, then you may want to use '{$class_str : $data}'.

overloads => [ '""', '0+' ]

If objects have overloaded these, use them to decompose the object.

tag => undef

To enable tag output, set this to '($class_str)$data'.

tag_method => 'FREEZE'

The method to search for to see if an object should be represented in the tag format.

Ioify options

io => 'null'

How IO objects will be decomposed.

Codeify options

code => 'null'

How CODE references will be decomposed.

Refify options

reference => '$_'

References will be ignored, and the actual value will be encoded.

dereference => '$referent$place'

When referring to a location in the reference, decompose with this.

Formatify options

format => 'null'

How a FORMAT will be encoded.

METHODS

new( ... )

Create a Jasonify object with the following options.

See "OPTIONS" for a description of the options and their default values.

exists( name, name, ... )

Determine if values exists for one or more settings.

Can be called as a class method or an object method.

get( name, name, ... )

Get one or more existing values for one or more settings. If passed no names, returns all parameters and values.

Can be called as a class method or an object method.

set( name => value, name => value, ... )

Change the "OPTIONS" settings. When called as a class method, changes default options. When called as an object method, changes the settings and returns a new object.

See "OPTIONS" for a description of the options and their default values.

NOTE: When called as a object method, this returns a new instance with the values set, so you will need to capture the return if you'd like to persist the change:

$jasonify = $jasonify->set( ... );

booleanify( value )

Returns the string that represents the true or false interpretation of value. If value is a scalar reference, calls itself with value dereferenced. Will return the value for undefify if value is not defined.

keyify( value )

Returns value as a key. NOTE: Numbers are always quoted when used as keys.

objectify( value )

Returns value as an object. Goes through a series of checks to format the object appropriately:

If a handler has been defined for the object with "add_handler( $class => \&code_ref )", then use that. If "tag" has been enabled, and the object has a method that corresponds to "tag_method", then that is used. If the object has a method that corresponds to "json_method", then that is used. If the object has overloaded any of "overloads => [ '""', '0+' ]", then use that to represent the $data portion of the object. If the object has an _attrkeyvals method, then that will be used to gather the elements of the object. If the object has none of those things, then the object is inspected and handled appropriately.

regexpify( value, delimiters )

Simply calls out to "stringify".

vstringify( value )

A representation of the VString. If "vformat" is specified, as a series of four digit hex values separated by '\\u'. If "vformat" is false, as a regular via "stringify".

scalarify( value )

This is the method called by "encode( value, ... )"

TODO: Returns value as a scalar. If value is not a reference, performs some magic to correctly print vstrings and numbers, otherwise assumes it's a string. If value is a reference, hands off to the correct function to create the string.

Handles reference loops.

decode( value, ... )

Decode one or more string representations of JSON.

NOTE: This method is not implemented yet, it is a placehold for future implementations.

encode( value, ... )

Encode one or more values to JSON formatted strings.

Can be called as a class or object method.

boolean( value )

If passed a value, returns the boolean for that value. If passed no value, retunrs the name of the class representing booleans.

Also aliased as bool( value ).

See "Jasonify::Boolean".

literal( value )

If passed a value, returns a representation of that value that, when encoded, will be exactly that value. If passed no value, returns the name of the class representing literals.

See "Jasonify::Literal".

number( value, ... )

If passed in a single value, returns a representation of that value that, when encoded, will be exactly that value. If passed in two or more values, returns a representation of that value when passed through to sprintf(). If passed no value, returns the name of the class representing numbers.

See "Jasonify::Number".

string( value )

If passed a value, returns a representation of that value that, when encoded, will be exactly that value as a string.

See "Jasonify::Literal".

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/rkleemann/Jasonify/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

TODO

  • Implement decode().

SEE ALSO

JSON, Datify

VERSION

This document describes version v0.20.050 of this module.

AUTHOR

Bob Kleemann <bobk@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2019 by Bob Kleemann.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)