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.16
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 actu‐
15       ally 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 look‐
45       ing for them in this order:
46
47               JSON::XS
48               JSON
49               JSON::DWIW
50               JSON::Syck
51
52       And loading the first one it finds.
53
54       You may change the order by specifying it on the "use JSON::Any" line:
55
56               use JSON::Any qw(DWIW Syck XS JSON);
57
58       Specifying an order that is missing one of the modules will prevent
59       that module from being used:
60
61               use JSON::Any qw(DWIW XS JSON);
62
63       This will check in that order, and will never attempt to load
64       JSON::Syck. This can also be set via the $ENV{JSON_ANY_ORDER} environ‐
65       ment variable.
66
67       WARNING: If you call JSON::Any with an empty list
68
69           use JSON::Any ();
70
71       It will skip the JSON package detection routines and will die loudly
72       that it couldn't find a package.
73

FUNCTIONS

75       "new"
76           Will take any of the parameters for the underlying system and pass
77           them through.  However these values don't map between JSON modules,
78           so, from a portability standpoint this is really only helpful for
79           those paramters that happen to have the same name. This will be
80           addressed in a future release.
81
82           The one parameter that is universally supported (to the extent that
83           is supported by the underlying JSON modules) is "utf8". When this
84           parameter is enabled all resulting JSON will be marked as unicode,
85           and all unicode strings in the input data structure will be pre‐
86           served as such.
87
88           The actual output will vary, for example JSON will encode and
89           decode unicode chars (the resulting JSON is not unicode) wheras
90           JSON::XS will emit unicode JSON.
91
92       "handlerType"
93           Takes no arguments, returns a string indicating which JSON Module
94           is in use.
95
96       "handler"
97           Takes no arguments, if called on an object returns the internal
98           JSON::* object in use.  Otherwise returns the JSON::* package we
99           are using for class methods.
100
101       "objToJson"
102           Takes a single argument, a hashref to be converted into JSON.  It
103           returns the JSON text in a scalar.
104
105       "to_json"
106       "Dump"
107       "encode"
108           Aliases for objToJson, can be used interchangeably, regardless of
109           the underlying JSON module.
110
111       "jsonToObj"
112           Takes a single argument, a string of JSON text to be converted back
113           into a hashref.
114
115       "from_json"
116       "Load"
117       "decode"
118           Aliases for jsonToObj, can be used interchangeably, regardless of
119           the underlying JSON module.
120

AUTHOR

122       Chris Thompson, "<cthom at cpan.org>" Chris Prather, "<perigrin at
123       cpan.org>"
124

BUGS

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

ACKNOWLEDGEMENTS

133       This module came about after discussions on irc.perl.org about the fact
134       that there were now six separate JSON perl modules with different
135       interfaces.
136
137       In the spirit of Class::Any, JSON::Any was created with the consider‐
138       able help of Matt 'mst' Trout.
139
140       Simon Wistow graciously supplied a patch for backwards compat with
141       JSON::XS versions previous to 2.01
142
143       San Dimas High School Football Rules!
144
146       Copyright 2007 Chris Thompson, some rights reserved.
147
148       This program is free software; you can redistribute it and/or modify it
149       under the same terms as Perl itself.
150
151
152
153perl v5.8.8                       2008-03-22                      JSON::Any(3)
Impressum