… | |
… | |
8 | |
8 | |
9 | # exported functions, croak on error |
9 | # exported functions, croak on error |
10 | |
10 | |
11 | $utf8_encoded_json_text = to_json $perl_hash_or_arrayref; |
11 | $utf8_encoded_json_text = to_json $perl_hash_or_arrayref; |
12 | $perl_hash_or_arrayref = from_json $utf8_encoded_json_text; |
12 | $perl_hash_or_arrayref = from_json $utf8_encoded_json_text; |
|
|
13 | |
|
|
14 | # objToJson and jsonToObj are exported for JSON |
|
|
15 | # compatibility, but should not be used in new code. |
13 | |
16 | |
14 | # oo-interface |
17 | # oo-interface |
15 | |
18 | |
16 | $coder = JSON::XS->new->ascii->pretty->allow_nonref; |
19 | $coder = JSON::XS->new->ascii->pretty->allow_nonref; |
17 | $pretty_printed_unencoded = $coder->encode ($perl_scalar); |
20 | $pretty_printed_unencoded = $coder->encode ($perl_scalar); |
… | |
… | |
36 | |
39 | |
37 | =head2 FEATURES |
40 | =head2 FEATURES |
38 | |
41 | |
39 | =over 4 |
42 | =over 4 |
40 | |
43 | |
41 | =item * correct handling of unicode issues |
44 | =item * correct unicode handling |
42 | |
45 | |
43 | This module knows how to handle Unicode, and even documents how and when |
46 | This module knows how to handle Unicode, and even documents how and when |
44 | it does so. |
47 | it does so. |
45 | |
48 | |
46 | =item * round-trip integrity |
49 | =item * round-trip integrity |
47 | |
50 | |
48 | When you serialise a perl data structure using only datatypes supported |
51 | When you serialise a perl data structure using only datatypes supported |
49 | by JSON, the deserialised data structure is identical on the Perl level. |
52 | by JSON, the deserialised data structure is identical on the Perl level. |
50 | (e.g. the string "2.0" doesn't suddenly become "2"). |
53 | (e.g. the string "2.0" doesn't suddenly become "2" just because it looks |
|
|
54 | like a number). |
51 | |
55 | |
52 | =item * strict checking of JSON correctness |
56 | =item * strict checking of JSON correctness |
53 | |
57 | |
54 | There is no guessing, no generating of illegal JSON texts by default, |
58 | There is no guessing, no generating of illegal JSON texts by default, |
55 | and only JSON is accepted as input by default (the latter is a security |
59 | and only JSON is accepted as input by default (the latter is a security |
… | |
… | |
66 | interface. |
70 | interface. |
67 | |
71 | |
68 | =item * reasonably versatile output formats |
72 | =item * reasonably versatile output formats |
69 | |
73 | |
70 | You can choose between the most compact guarenteed single-line format |
74 | You can choose between the most compact guarenteed single-line format |
71 | possible (nice for simple line-based protocols), a pure-ascii format (for |
75 | possible (nice for simple line-based protocols), a pure-ascii format |
72 | when your transport is not 8-bit clean), or a pretty-printed format (for |
76 | (for when your transport is not 8-bit clean, still supports the whole |
73 | when you want to read that stuff). Or you can combine those features in |
77 | unicode range), or a pretty-printed format (for when you want to read that |
74 | whatever way you like. |
78 | stuff). Or you can combine those features in whatever way you like. |
75 | |
79 | |
76 | =back |
80 | =back |
77 | |
81 | |
78 | =cut |
82 | =cut |
79 | |
83 | |
80 | package JSON::XS; |
84 | package JSON::XS; |
81 | |
85 | |
|
|
86 | use strict; |
|
|
87 | |
82 | BEGIN { |
88 | BEGIN { |
83 | $VERSION = '0.5'; |
89 | our $VERSION = '0.8'; |
84 | @ISA = qw(Exporter); |
90 | our @ISA = qw(Exporter); |
85 | |
91 | |
86 | @EXPORT = qw(to_json from_json); |
92 | our @EXPORT = qw(to_json from_json objToJson jsonToObj); |
87 | require Exporter; |
93 | require Exporter; |
88 | |
94 | |
89 | require XSLoader; |
95 | require XSLoader; |
90 | XSLoader::load JSON::XS::, $VERSION; |
96 | XSLoader::load JSON::XS::, $VERSION; |
91 | } |
97 | } |