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
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.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.
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.
- 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.
- deny_blessed_object
-
Useless? Not yet implemented.
- disable_UTF8
-
If this option is set, UTF8 flag in strings generated by
encode
/decode
is off. - allow_tied
-
Enable.
- 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.
- literal_value
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 138 (sec).
JSON::XS takes 4.
TODO
SEE ALSO
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.