JSON-Streaming-Writer
view release on metacpan or search on metacpan
--- #YAML:1.0
name: JSON-Streaming-Writer
version: 0.03
abstract: Generate JSON output in a streaming manner
author:
- Martin Atkins <mart@degeneration.co.uk>
license: unknown
distribution_type: module
configure_requires:
ExtUtils::MakeMaker: 0
build_requires:
ExtUtils::MakeMaker: 0
requires:
B: 0
lib/JSON/Streaming/Writer.pm view on Meta::CPAN
if ($self->_state != ROOT_STATE && ! $self->{intentionally_ending_early}) {
warn "JSON::Streaming::Writer object was destroyed with incomplete output";
}
}
1;
=head1 NAME
JSON::Streaming::Writer - Generate JSON output in a streaming manner
=head1 SYNOPSIS
my $jsonw = JSON::Streaming::Writer->for_stream($fh)
$jsonw->start_object();
$jsonw->add_simple_property("someName" => "someValue");
$jsonw->add_simple_property("someNumber" => 5);
$jsonw->start_property("someObject");
$jsonw->start_object();
$jsonw->add_simple_property("someOtherName" => "someOtherValue");
lib/JSON/Streaming/Writer.pm view on Meta::CPAN
=head1 DESCRIPTION
Most JSON libraries work in terms of in-memory data structures. In Perl,
JSON serializers often expect to be provided with a HASH or ARRAY ref
containing all of the data you want to serialize.
This library allows you to generate syntactically-correct JSON without
first assembling your complete data structure in memory. This allows
large structures to be returned without requiring those
structures to be memory-resident, and also allows parts of the output
to be made available to a streaming-capable JSON parser while
the rest of the output is being generated, which may improve
performance of JSON-based network protocols.
=head1 RAW API
The raw API allows the caller precise control over the generated
data structure by providing explicit methods for each fundamental JSON
construct.
As a general rule, methods with names starting with C<start_> and C<end_>
lib/JSON/Streaming/Writer.pm view on Meta::CPAN
figure out a sensible JSON representation for them. You can mix use of the raw
and DWIM APIs to allow you to exercise fine control where required but use
a simpler API for normal cases.
=head2 add_value($value)
Produces a JSON value representing the given Perl value. This library can handle
Perl strings, integers (i.e. scalars that have most recently been used as numbers),
references to the values 0 and 1 representing booleans and C<undef> representing
a JSON C<null>. It can also accept ARRAY and HASH refs that contain such values
and produce JSON array and object values recursively, much like a non-streaming
JSON producer library would do.
This method is a wrapper around the corresponding raw API calls, so the error
messages it generates will often refer to the underlying raw API.
=head2 add_property($name, $value)
Produces a property inside a JSON object whose value is derived from the provided
value using the same mappings as used by C<add_value>. This can only be used
inside the context of an object, and is really just a wrapper around a C<start_property>,
( run in 0.266 second using v1.01-cache-2.11-cpan-4d50c553e7e )