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

NAME

6       JSON::Any - Wrapper Class for the various JSON classes.
7

VERSION

9       Version 1.22
10

SYNOPSIS

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

FUNCTIONS

87       "new"
88           Will take any of the parameters for the underlying system and pass
89           them through. However these values don't map between JSON modules,
90           so, from a portability standpoint this is really only helpful for
91           those paramters that happen to have the same name. This will be
92           addressed in a future release.
93
94           The one parameter that is universally supported (to the extent that
95           is supported by the underlying JSON modules) is "utf8". When this
96           parameter is enabled all resulting JSON will be marked as unicode,
97           and all unicode strings in the input data structure will be
98           preserved as such.
99
100           Also note that the "allow_blessed" parameter is recognised by all
101           the modules that throw exceptions when a blessed reference is given
102           them meaning that setting it to true works for all modules. Of
103           course, that means that you cannot set it to false intentionally in
104           order to always get such exceptions.
105
106           The actual output will vary, for example JSON will encode and
107           decode unicode chars (the resulting JSON is not unicode) wheras
108           JSON::XS will emit unicode JSON.
109
110       "handlerType"
111           Takes no arguments, returns a string indicating which JSON Module
112           is in use.
113
114       "handler"
115           Takes no arguments, if called on an object returns the internal
116           JSON::* object in use.  Otherwise returns the JSON::* package we
117           are using for class methods.
118
119       "true"
120           Takes no arguments, returns the special value that the internal
121           JSON object uses to map to a JSON "true" boolean.
122
123       "false"
124           Takes no arguments, returns the special value that the internal
125           JSON object uses to map to a JSON "false" boolean.
126
127       "objToJson"
128           Takes a single argument, a hashref to be converted into JSON.  It
129           returns the JSON text in a scalar.
130
131       "to_json"
132       "Dump"
133       "encode"
134           Aliases for objToJson, can be used interchangeably, regardless of
135           the underlying JSON module.
136
137       "jsonToObj"
138           Takes a single argument, a string of JSON text to be converted back
139           into a hashref.
140
141       "from_json"
142       "Load"
143       "decode"
144           Aliases for jsonToObj, can be used interchangeably, regardless of
145           the underlying JSON module.
146

AUTHORS

148       Chris Thompson "cthom at cpan.org"
149
150       Chris Prather "chris at prather.org"
151
152       Robin Berjon "robin at berjon.com"
153
154       Marc Mims "marc at questright.com"
155
156       Tomas Doran "bobtfish at bobtfish.net"
157

BUGS

159       Please report any bugs or feature requests to "bug-json-any at
160       rt.cpan.org", or through the web interface at
161       http://rt.cpan.org/NoAuth/ReportBug.html?Queue=JSON-Any
162       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=JSON-Any>.  I will be
163       notified, and then you'll automatically be notified of progress on your
164       bug as I make changes.
165

ACKNOWLEDGEMENTS

167       This module came about after discussions on irc.perl.org about the fact
168       that there were now six separate JSON perl modules with different
169       interfaces.
170
171       In the spirit of Class::Any, JSON::Any was created with the
172       considerable help of Matt 'mst' Trout.
173
174       Simon Wistow graciously supplied a patch for backwards compat with
175       JSON::XS versions previous to 2.01
176
177       San Dimas High School Football Rules!
178
180       Copyright 2007-2009 Chris Thompson, some rights reserved.
181
182       This program is free software; you can redistribute it and/or modify it
183       under the same terms as Perl itself.
184
185
186
187perl v5.12.0                      2009-10-13                      JSON::Any(3)
Impressum