JSON::PP(3)

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::PP::true
    Returns JSON true value which is blessed object. It "isa" JSON::PP::Boolean object.

JSON::PP::false
    Returns JSON false value which is blessed object. It "isa" JSON::PP::Boolean object.

JSON::PP::null
    Returns "undef".

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, 512.

    When a large value is set, it may raise a warning 'Deep recursion on subroutin'.

max_size
relaxed
allow_blessed
convert_blessed
filter_json_object
filter_json_single_key_object
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.

    Will be obsoleted.

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

allow_tied
    Now disable.

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 (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.

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

MAPPING
Now same as JSON::XS.

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.