… | |
… | |
9 | # exported functions, they croak on error |
9 | # exported functions, they croak on error |
10 | # and expect/generate UTF-8 |
10 | # and expect/generate UTF-8 |
11 | |
11 | |
12 | $utf8_encoded_json_text = to_json $perl_hash_or_arrayref; |
12 | $utf8_encoded_json_text = to_json $perl_hash_or_arrayref; |
13 | $perl_hash_or_arrayref = from_json $utf8_encoded_json_text; |
13 | $perl_hash_or_arrayref = from_json $utf8_encoded_json_text; |
14 | |
|
|
15 | # objToJson and jsonToObj aliases to to_json and from_json |
|
|
16 | # are exported for compatibility to the JSON module, |
|
|
17 | # but should not be used in new code. |
|
|
18 | |
14 | |
19 | # OO-interface |
15 | # OO-interface |
20 | |
16 | |
21 | $coder = JSON::XS->new->ascii->pretty->allow_nonref; |
17 | $coder = JSON::XS->new->ascii->pretty->allow_nonref; |
22 | $pretty_printed_unencoded = $coder->encode ($perl_scalar); |
18 | $pretty_printed_unencoded = $coder->encode ($perl_scalar); |
… | |
… | |
88 | use strict; |
84 | use strict; |
89 | |
85 | |
90 | our $VERSION = '1.4'; |
86 | our $VERSION = '1.4'; |
91 | our @ISA = qw(Exporter); |
87 | our @ISA = qw(Exporter); |
92 | |
88 | |
93 | our @EXPORT = qw(to_json from_json objToJson jsonToObj); |
89 | our @EXPORT = qw(to_json from_json); |
94 | |
90 | |
95 | use Exporter; |
91 | use Exporter; |
96 | use XSLoader; |
92 | use XSLoader; |
97 | |
93 | |
98 | =head1 FUNCTIONAL INTERFACE |
94 | =head1 FUNCTIONAL INTERFACE |
… | |
… | |
806 | still relatively early in its development. If you keep reporting bugs they |
802 | still relatively early in its development. If you keep reporting bugs they |
807 | will be fixed swiftly, though. |
803 | will be fixed swiftly, though. |
808 | |
804 | |
809 | =cut |
805 | =cut |
810 | |
806 | |
811 | our $true = do { bless \(my $dummy = 1), "JSON::XS::Boolean" }; |
807 | our $true = do { bless \(my $dummy = "1"), "JSON::XS::Boolean" }; |
812 | our $false = do { bless \(my $dummy = 0), "JSON::XS::Boolean" }; |
808 | our $false = do { bless \(my $dummy = "0"), "JSON::XS::Boolean" }; |
813 | |
809 | |
814 | sub true() { $true } |
810 | sub true() { $true } |
815 | sub false() { $false } |
811 | sub false() { $false } |
816 | |
812 | |
817 | sub is_bool($) { |
813 | sub is_bool($) { |