JSON::PP - An experimental JSON::XS compatible Pure Perl module.
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});
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.
perhaps correct unicode handling
This module knows how to handle Unicode (perhaps), but not yet documents how and when it does so.
In Perl5.6x, Unicode handling requires Unicode::String module.
Perl 5.005_xx, Unicode handling is disable currenlty.
round-trip integrity
This module solved the problem pointed out by JSON::XS using B module.
strict checking of JSON correctness
I want to bring close to XS. How do you want to carry out?
you can set strict decoding method.
strict
slow
Compared to other JSON modules, this module does not compare favourably in terms of speed. Very slowly!
simple to use
This module became very simple. Since its interface were anyway made the same as JSON::XS.
reasonably versatile output formats
See to JSON::XS.
See to JSON::XS. objToJson is an alias.
objToJson
See to JSON::XS. jsonToObj is an alias.
jsonToObj
Returns JSON true value which is blessed object. It isa JSON::PP::Boolean object.
isa
Returns JSON false value which is blessed object. It isa JSON::PP::Boolean object.
Returns undef.
undef
Returns JSON::PP object.
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.
Currently this module always handles UTF-16 as UTF-16BE.
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();
See JSON::XS.
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).
Not yet implemented.
See to JSON::XS. Strictly, this module does not carry out equivalent to XS. By default, 512.
When a large value is set, it may raise a warning 'Deep recursion on subroutin'.
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.
Accessor.
$json->property(utf8 => 1); # $json->utf8(1); $value = $json->property('utf8'); # returns 1.
See "BLESSED OBJECT" in JSON's self convert function.
Will be obsoleted.
If this option is set, UTF8 flag in strings generated by encode/decode is off.
encode
decode
Now disable.
Allows to decode single quoted strings.
Unlike JSON module, this module does not encode Perl string into single quoted string any longer.
Allows to decode bare key of member.
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.
For JSON format, unescaped [\x00-\x1f\x22\x2f\x5c] strings are invalid and JSON::XS decodes just like that (except for \x2f). While this module can deocde thoese. But if this option is set, the module strictly decodes.
This option will be obsoleted and 'un-strict' will be added insted.
By default, JSON::PP encodes strings without escaping slash (U+002F). Setting the option to escape slash.
Now same as JSON::XS.
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.
It is troublesome.
Under the cleaning.
JSON, JSON::XS
RFC4627
Makamaka Hannyaharamitu, <makamaka[at]cpan.org>
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.
To install JSON, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSON
CPAN shell
perl -MCPAN -e shell install JSON
For more information on module installation, please visit the detailed CPAN module installation guide.