1JSON::PP(3)           User Contributed Perl Documentation          JSON::PP(3)
2
3
4

NAME

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

SYNOPSIS

9        use JSON::PP;
10
11        $obj       = from_json($json_text);
12        $json_text = to_json($obj);
13
14        # or
15
16        $obj       = jsonToObj($json_text);
17        $json_text = objToJson($obj);
18
19        $json = new JSON;
20        $json_text = $json->ascii->pretty($obj);
21
22        # you can set options to functions.
23
24        $json_text = to_json($obj, {ascii => 1, intend => 2});
25        $obj       = from_json($json_text, {utf8 => 0});
26

DESCRIPTION

28       This module is JSON::XS compatible Pure Perl module.  ( Perl better
29       than 5.008 is recommended)
30
31       Module variables ($JSON::*) were abolished.
32
33       JSON::PP will be renamed JSON (JSON-2.0).
34
35       Many things including error handling are learned from JSON::XS.  For
36       t/02_error.t compatible, error messages was copied partially from
37       JSON::XS.
38
39       FEATURES
40
41       * perhaps correct unicode handling
42           This module knows how to handle Unicode (perhaps), but not yet doc‐
43           uments how and when it does so.
44
45           In Perl5.6x, Unicode handling requires Unicode::String module.
46
47           Perl 5.005_xx, Unicode handling is disable currenlty.
48
49       * round-trip integrity
50           This module solved the problem pointed out by JSON::XS using B mod‐
51           ule.
52
53       * strict checking of JSON correctness
54           I want to bring close to XS.  How do you want to carry out?
55
56           you can set "strict" decoding method.
57
58       * slow
59           Compared to other JSON modules, this module does not compare
60           favourably in terms of speed. Very slowly!
61
62       * simple to use
63           This module became very simple.  Since its interface were anyway
64           made the same as JSON::XS.
65
66       * reasonably versatile output formats
67           See to JSON::XS.
68

FUNCTIONS

70       to_json
71           See to JSON::XS.  "objToJson" is an alias.
72
73       from_json
74           See to JSON::XS.  "jsonToObj" is an alias.
75
76       JSON::PP::true
77           Returns JSON true value which is blessed object.  It "isa"
78           JSON::PP::Boolean object.
79
80       JSON::PP::false
81           Returns JSON false value which is blessed object.  It "isa"
82           JSON::PP::Boolean object.
83
84       JSON::PP::null
85           Returns "undef".
86

METHODS

88       new Returns JSON::PP object.
89
90       ascii
91           See to JSON::XS.
92
93           In Perl 5.6, this method requires Unicode::String.  If you don't
94           have Unicode::String, the method is always set to false and warns.
95
96           In Perl 5.005, this option is currently disable.
97
98       latin1
99           See to JSON::XS.
100
101           In Perl 5.6, this method requires Unicode::String.  If you don't
102           have Unicode::String, the method is always set to false and warns.
103
104           In Perl 5.005, this option is currently disable.
105
106       utf8
107           See to JSON::XS.
108
109           Currently this module always handles UTF-16 as UTF-16BE.
110
111       pretty
112           See to JSON::XS.
113
114       indent
115           See to JSON::XS.  Strictly, this module does not carry out equiva‐
116           lent to XS.
117
118            $json->indent(4);
119
120           is not the same as this:
121
122            $json->indent();
123
124       space_before
125           See to JSON::XS.
126
127       space_after
128           See JSON::XS.
129
130       canonical
131           See to JSON::XS.  Strictly, this module does not carry out equiva‐
132           lent to XS.  This method can take a subref for sorting (see to
133           JSON).
134
135       allow_nonref
136           See to JSON::XS.
137
138       shrink
139           Not yet implemented.
140
141       max_depth
142           See to JSON::XS.  Strictly, this module does not carry out equiva‐
143           lent to XS.  By default, 512.
144
145           When a large value is set, it may raise a warning 'Deep recursion
146           on subroutin'.
147
148       max_size
149       relaxed
150       allow_blessed
151       convert_blessed
152       filter_json_object
153       filter_json_single_key_object
154       encode
155           See to JSON::XS.
156
157       decode
158           See to JSON::XS.  In Perl 5.6, if you don't have Unicode::String,
159           the method can't handle UTF-16(BE) char and returns as is.
160
161       property
162           Accessor.
163
164            $json->property(utf8 => 1); # $json->utf8(1);
165
166            $value = $json->property('utf8'); # returns 1.
167
168       self_encode
169           See "BLESSED OBJECT" in JSON's self convert function.
170
171           Will be obsoleted.
172
173       disable_UTF8
174           If this option is set, UTF8 flag in strings generated by
175           "encode"/"decode" is off.
176
177       allow_tied
178           Now disable.
179
180       singlequote
181           Allows to decode single quoted strings.
182
183           Unlike JSON module, this module does not encode Perl string into
184           single quoted string any longer.
185
186       allow_barekey
187           Allows to decode bare key of member.
188
189       allow_bigint
190           When json text has any integer in decoding more than Perl can't
191           handle, If this option is on, they are converted into Math::BigInt
192           objects.
193
194       strict
195           For JSON format, unescaped [\x00-\x1f\x22\x2f\x5c] strings are
196           invalid and JSON::XS decodes just like that (except for \x2f).
197           While this module can deocde thoese.  But if this option is set,
198           the module strictly decodes.
199
200           This option will be obsoleted and 'un-strict' will be added insted.
201
202       escape_slash
203           By default, JSON::PP encodes strings without escaping slash
204           (U+002F).  Setting the option to escape slash.
205

MAPPING

207       Now same as JSON::XS.
208

COMPARISON

210       Using a benchmark program in the JSON::XS (v1.11) distribution.
211
212        module     ⎪     encode ⎪     decode ⎪
213        -----------⎪------------⎪------------⎪
214        JSON::PP   ⎪  11092.260 ⎪   4482.033 ⎪
215        -----------+------------+------------+
216        JSON::XS   ⎪ 341513.380 ⎪ 226138.509 ⎪
217        -----------+------------+------------+
218
219       In case t/12_binary.t (JSON::XS distribution).  (shrink of JSON::PP has
220       no effect.)
221
222       JSON::PP takes 147 (sec).
223
224       JSON::XS takes 4.
225

TODO

227       Document!
228           It is troublesome.
229
230       clean up
231           Under the cleaning.
232

SEE ALSO

234       JSON, JSON::XS
235
236       RFC4627
237

AUTHOR

239       Makamaka Hannyaharamitu, <makamaka[at]cpan.org>
240
242       Copyright 2007 by Makamaka Hannyaharamitu
243
244       This library is free software; you can redistribute it and/or modify it
245       under the same terms as Perl itself.
246
247
248
249perl v5.8.8                       2007-05-10                       JSON::PP(3)
Impressum