Commit | Line | Data |
ebf1e433 |
1 | use strict; |
2 | use warnings FATAL => 'all'; |
3 | |
4 | use Test::Without::Module 'Cpanel::JSON::XS'; |
5 | use Test::More; |
6 | use JSON::MaybeXS qw/:legacy/; |
7 | |
8 | |
9 | |
10 | my $in = '[1, 2, 3, 4]'; |
11 | |
12 | |
13 | my $arr = from_json($in); |
14 | my $j = to_json($arr); |
15 | is($j, '[1,2,3,4]'); |
16 | is(ref($arr), 'ARRAY'); |
17 | |
18 | done_testing; |
19 | |
20 | __END__ |
21 | |
22 | to_json |
23 | $json_text = to_json($perl_scalar) |
24 | |
25 | Converts the given Perl data structure to a json string. |
26 | |
27 | This function call is functionally identical to: |
28 | |
29 | $json_text = JSON->new->encode($perl_scalar) |
30 | |
31 | from_json |
32 | $perl_scalar = from_json($json_text) |
33 | |
34 | The opposite of "to_json": expects a json string and tries to parse it, |
35 | returning the resulting reference. |
36 | |
37 | This function call is functionally identical to: |
38 | |
39 | $perl_scalar = JSON->decode($json_text) |