Makamaka Hannyaharamitu > JSON-1.14 > JSON::PP

Download:
JSON-1.14.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  3
View Bugs
Report a bug
Module Version: 0.96   Source   Latest Release: JSON-2.16

NAME ^

JSON::PP - An experimental JSON::XS compatible Pure Perl module.

SYNOPSIS ^

 use JSON::PP;

 $obj       = from_json($json_text);
 $json_text = to_json($obj);

 # or

 $obj       = jsonToObj($json_text);
 $json_text = objToJson($obj);

 $json = new JSON;
 $json_text = $json->ascii->pretty($obj);

 # you can set options to functions.

 $json_text = to_json($obj, {ascii => 1, intend => 2});
 $obj       = from_json($json_text, {utf8 => 0});

DESCRIPTION ^

This module is JSON::XS compatible Pure Perl module. ( Perl better than 5.008 is recommended)

Module variables ($JSON::*) were abolished.

JSON::PP will be renamed JSON (JSON-2.0).

Many things including error handling are learned from JSON::XS. For t/02_error.t compatible, error messages was copied partially from JSON::XS.

FEATURES

FUNCTIONS ^

to_json

See to JSON::XS. objToJson is an alias.

from_json

See to JSON::XS. jsonToObj is an alias.

JSON::true

Returns JSON true value which is blessed object. It isa JSON::Literal object.

JSON::false

Returns JSON false value which is blessed object. It isa JSON::Literal object.

JSON::null

Returns JSON null value which is blessed object. It isa JSON::Literal object.

METHODS ^

new

Returns JSON::PP object.

ascii

See to JSON::XS.

In Perl 5.6, this method requires Unicode::String. If you don't have Unicode::String, the method is always set to false and warns.

In Perl 5.005, this option is currently disable.

latin1

See to JSON::XS.

In Perl 5.6, this method requires Unicode::String. If you don't have Unicode::String, the method is always set to false and warns.

In Perl 5.005, this option is currently disable.

utf8

See to JSON::XS.

Currently this module always handles UTF-16 as UTF-16BE.

pretty

See to JSON::XS.

indent

See to JSON::XS. Strictly, this module does not carry out equivalent to XS.

 $json->indent(4);

is not the same as this:

 $json->indent();
space_before

See to JSON::XS.

space_after

See JSON::XS.

canonical

See to JSON::XS. Strictly, this module does not carry out equivalent to XS. This method can take a subref for sorting (see to JSON).

allow_nonref

See to JSON::XS.

shrink

Not yet implemented.

max_depth

See to JSON::XS. Strictly, this module does not carry out equivalent to XS. By default, not 512 (JSON::XS) but 32.

encode

See to JSON::XS.

decode

See to JSON::XS. In Perl 5.6, if you don't have Unicode::String, the method can't handle UTF-16(BE) char and returns as is.

property

Accessor.

 $json->property(utf8 => 1); # $json->utf8(1);

 $value = $json->property('utf8'); # returns 1.
self_encode

See "BLESSED OBJECT" in JSON's self convert function.

disable_UTF8

If this option is set, UTF8 flag in strings generated by encode/decode is off.

allow_tied

Enable.

This option will be obsoleted.

singlequote

Allows to decode single quoted strings.

Unlike JSON module, this module does not encode Perl string into single quoted string any longer.

allow_barekey

Allows to decode bare key of member.

allow_bigint

When json text has any integer in decoding more than Perl can't handle, If this option is on, they are converted into Math::BigInt objects.

strict

For JSON format, unescaped [\x00-\x1f\x22\x2f\x5c] strings are invalid and JSON::XS decodes just like that. While this module can deocde thoese. But if this option is set, the module strictly decodes.

escape_slash

By default, JSON::PP encodes strings without escaping slash (U+002F). Setting the option to escape slash.

literal_value

MAPPING ^

COMPARISON ^

Using a benchmark program in the JSON::XS (v1.11) distribution.

 module     |     encode |     decode |
 -----------|------------|------------|
 JSON::PP   |  11092.260 |   4482.033 |
 -----------+------------+------------+
 JSON::XS   | 341513.380 | 226138.509 |
 -----------+------------+------------+

In case t/12_binary.t (JSON::XS distribution). (shrink of JSON::PP has no effect.)

JSON::PP takes 147 (sec).

JSON::XS takes 4.

TODO ^

Document!

It is troublesome.

clean up

Under the cleaning.

SEE ALSO ^

JSON, JSON::XS

RFC4627

AUTHOR ^

Makamaka Hannyaharamitu, <makamaka[at]cpan.org>

COPYRIGHT AND LICENSE ^

Copyright 2007 by Makamaka Hannyaharamitu

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.