NAME
Data::Record::Serialize::Encode::json - encoded a record as JSON
VERSION
version 2.05
SYNOPSIS
use Data::Record::Serialize;
my $s = Data::Record::Serialize->new( encode => 'json', %options );
$s->send( \%record );
DESCRIPTION
Data::Record::Serialize::Encode::json encodes a record as JSONL.
If a field's type is N or I, it will be properly encoded by JSON as a number. Field's with type S are forced to be strings.
Boolean fields (type B) are transformed into values recognized by the back-end encoder.
The output consists of one JSON object per line, and is mostly easily read by an incremental decoder, e.g.
use JSON::MaybeXS;
@data = JSON->new->incr_parse( $json );
It performs the Data::Record::Serialize::Role::Encode role.
Transformations of Objects
If the "allow_blessed" and "convert_blessed" flags are set, the underlying JSON module will invoke the TO_JSON method any values which are objects, and which provide that method.
Unfortunately, these settings interact with the default values for "stringify" in Data::Record::Serialize and "numify" in Data::Record::Serialize set by this module, which are both set to 1.
Stringification and numification are performed before being sent to the JSON serializer, so it will not see the original object, and thus will not run its TO_JSON method.
To remedy this, it's simplest to turn off stringification and numification for individual attributes using "Data::Record::Serialize"/Field Selection Specifcations>. For example, if fields string_obj1 and num_obj1 are objects which do not overload numification and stringification, but do support TO_JSON, then setting
stringify => ['-string_obj2'],
numify => ['-num_obj2'],
allow_blessed => 1,
convert_blessed => 1,
will result in TO_JSON being passed the actual objects.
METHODS
to_bool
$bool = $self->to_bool( $truthy );
Convert a truthy value to something that the JSON encoders will recognize as a boolean.
CONSTRUCTOR OPTIONS
These are equivalent to the methods operating on the underlying JSON object (see JSON::PP).
- ascii => boolean
- latin1 => boolean
- utf8 => boolean
- pretty => boolean
- indent => boolean
- space_before => boolean
- space_after => boolean
- canonical => boolean
- allow_blessed => boolean
- convert_blessed => boolean
SUPPORT
Bugs
Please report any bugs or feature requests to bug-data-record-serialize@rt.cpan.org or through the web interface at: https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Record-Serialize
Source
Source is available at
https://gitlab.com/djerius/data-record-serialize
and may be cloned from
https://gitlab.com/djerius/data-record-serialize.git
SEE ALSO
Please see those modules/websites for more information related to this module.
AUTHOR
Diab Jerius <djerius@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007