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

NAME

6       JSON::Any - (DEPRECATED) Wrapper Class for the various JSON classes
7

VERSION

9       version 1.39
10

SYNOPSIS

12           use JSON::Any;
13           my $j = JSON::Any->new;
14           my $json = $j->objToJson({foo=>'bar', baz=>'quux'});
15           my $obj = $j->jsonToObj($json);
16

DESCRIPTION

18       This module tries to provide a coherent API to bring together the
19       various JSON modules currently on CPAN. This module will allow you to
20       code to any JSON API and have it work regardless of which JSON module
21       is actually installed.
22
23           use JSON::Any;
24
25           my $j = JSON::Any->new;
26
27           $json = $j->objToJson({foo=>'bar', baz=>'quux'});
28           $obj = $j->jsonToObj($json);
29
30       or
31
32           $json = $j->encode({foo=>'bar', baz=>'quux'});
33           $obj = $j->decode($json);
34
35       or
36
37           $json = $j->Dump({foo=>'bar', baz=>'quux'});
38           $obj = $j->Load($json);
39
40       or
41
42           $json = $j->to_json({foo=>'bar', baz=>'quux'});
43           $obj = $j->from_json($json);
44
45       or without creating an object:
46
47           $json = JSON::Any->objToJson({foo=>'bar', baz=>'quux'});
48           $obj = JSON::Any->jsonToObj($json);
49
50       On load, JSON::Any will find a valid JSON module in your @INC by
51       looking for them in this order:
52
53           Cpanel::JSON::XS
54           JSON::XS
55           JSON::PP
56           JSON
57           JSON::DWIW
58
59       And loading the first one it finds.
60
61       You may change the order by specifying it on the "use JSON::Any" line:
62
63           use JSON::Any qw(DWIW XS CPANEL JSON PP);
64
65       Specifying an order that is missing modules will prevent those module
66       from being used:
67
68           use JSON::Any qw(CPANEL PP); # same as JSON::MaybeXS
69
70       This will check in that order, and will never attempt to load JSON::XS,
71       "JSON" in JSON.pm, or JSON::DWIW. This can also be set via the
72       $ENV{JSON_ANY_ORDER} environment variable.
73
74       JSON::Syck has been deprecated by its author, but in the attempt to
75       still stay relevant as a "Compatibility Layer" JSON::Any still supports
76       it. This support however has been made optional starting with JSON::Any
77       1.19. In deference to a bug request starting with JSON.pm 1.20,
78       JSON::Syck and other deprecated modules will still be installed, but
79       only as a last resort and will now include a warning.
80
81           use JSON::Any qw(Syck XS JSON);
82
83       or
84
85           $ENV{JSON_ANY_ORDER} = 'Syck XS JSON';
86
87       At install time, JSON::Any will attempt to install JSON::PP as a
88       reasonable fallback if you do not appear have any backends installed on
89       your system.
90
91       WARNING: If you call JSON::Any with an empty list
92
93           use JSON::Any ();
94
95       It will skip the JSON package detection routines and will die loudly
96       that it couldn't find a package.
97

DEPRECATION NOTICE

99       The original need for JSON::Any has been solved (quite some time ago
100       actually). If you're producing new code it is recommended to use
101       JSON::MaybeXS which will optionally use Cpanel::JSON::XS for speed
102       purposes.
103
104       JSON::Any will continue to be maintained for compatibility with
105       existing code, but for new code you should strongly consider using
106       JSON::MaybeXS instead.
107

WARNING

109       JSON::XS 3.0 or higher has a conflict with any version of JSON.pm less
110       than 2.90 when you use JSON.pm's "-support_by_pp" option, which
111       JSON::Any enables by default.
112
113       This situation should only come up with JSON::Any if you have JSON.pm
114       2.61 or lower and JSON::XS 3.0 or higher installed, and you use JSON.pm
115       via "use JSON::Any qw(JSON);" or the "JSON_ANY_ORDER" environment
116       variable.
117
118       If you run into an issue where you're getting recursive inheritance
119       errors in a Types::Serialiser package, please try upgrading JSON.pm to
120       2.90 or higher.
121

METHODS

123   "new"
124       Will take any of the parameters for the underlying system and pass them
125       through. However these values don't map between JSON modules, so, from
126       a portability standpoint this is really only helpful for those
127       parameters that happen to have the same name.
128
129       The one parameter that is universally supported (to the extent that is
130       supported by the underlying JSON modules) is "utf8". When this
131       parameter is enabled all resulting JSON will be marked as unicode, and
132       all unicode strings in the input data structure will be preserved as
133       such.
134
135       Also note that the "allow_blessed" parameter is recognised by all the
136       modules that throw exceptions when a blessed reference is given them
137       meaning that setting it to true works for all modules. Of course, that
138       means that you cannot set it to false intentionally in order to always
139       get such exceptions.
140
141       The actual output will vary, for example JSON will encode and decode
142       unicode chars (the resulting JSON is not unicode) whereas JSON::XS will
143       emit unicode JSON.
144
145   "handlerType"
146       Takes no arguments, returns a string indicating which JSON Module is in
147       use.
148
149   "handler"
150       Takes no arguments, if called on an object returns the internal JSON::*
151       object in use.  Otherwise returns the JSON::* package we are using for
152       class methods.
153
154   "true"
155       Takes no arguments, returns the special value that the internal JSON
156       object uses to map to a JSON "true" boolean.
157
158   "false"
159       Takes no arguments, returns the special value that the internal JSON
160       object uses to map to a JSON "false" boolean.
161
162   "objToJson"
163       Takes a single argument, a hashref to be converted into JSON.  It
164       returns the JSON text in a scalar.
165
166   "to_json"
167   "Dump"
168   "encode"
169       Aliases for "objToJson", can be used interchangeably, regardless of the
170       underlying JSON module.
171
172   "jsonToObj"
173       Takes a single argument, a string of JSON text to be converted back
174       into a hashref.
175
176   "from_json"
177   "Load"
178   "decode"
179       Aliases for "jsonToObj", can be used interchangeably, regardless of the
180       underlying JSON module.
181

ACKNOWLEDGEMENTS

183       This module came about after discussions on irc.perl.org about the fact
184       that there were now six separate JSON perl modules with different
185       interfaces.
186
187       In the spirit of Class::Any, JSON::Any was created with the
188       considerable help of Matt 'mst' Trout.
189
190       Simon Wistow graciously supplied a patch for backwards compatibility
191       with JSON::XS versions previous to 2.01
192
193       San Dimas High School Football Rules!
194

AUTHORS

196       •   Chris Thompson <cthom@cpan.org>
197
198       •   Chris Prather <chris@prather.org>
199
200       •   Robin Berjon <robin@berjon.com>
201
202       •   Marc Mims <marc@questright.com>
203
204       •   Tomas Doran <bobtfish@bobtfish.net>
205

CONTRIBUTORS

207       •   Karen Etheridge <ether@cpan.org>
208
209       •   יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
210
211       •   Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
212
213       •   Justin Hunter <justin.d.hunter@gmail.com>
214
215       •   Todd Rinaldo <toddr@cpan.org>
216
217       •   Matthew Horsfall <wolfsage@gmail.com>
218
220       This software is copyright (c) 2007 by Chris Thompson.
221
222       This is free software; you can redistribute it and/or modify it under
223       the same terms as the Perl 5 programming language system itself.
224
225
226
227perl v5.36.0                      2022-07-22                      JSON::Any(3)
Impressum