2 use warnings FATAL => 'all';
4 use Test::Without::Module 'Cpanel::JSON::XS';
6 use JSON::MaybeXS qw/:legacy/;
8 my $in = '[1, 2, 3, 4]';
10 my $arr = from_json($in);
11 my $j = to_json($arr);
13 is(ref($arr), 'ARRAY');
15 my $json = 'JSON::MaybeXS';
16 diag "using invocant: $json";
18 do { eval { $json->from_json($in) }; $@ },
19 qr/from_json should not be called as a method/,
20 'blessed invocant detected in from_json',
24 do { eval { $json->to_json($arr, { blah => 1 } ) }; $@ },
25 qr/to_json should not be called as a method/,
26 'blessed invocant detected in to_json',
34 $json_text = to_json($perl_scalar)
36 Converts the given Perl data structure to a json string.
38 This function call is functionally identical to:
40 $json_text = JSON->new->encode($perl_scalar)
43 $perl_scalar = from_json($json_text)
45 The opposite of "to_json": expects a json string and tries to parse it,
46 returning the resulting reference.
48 This function call is functionally identical to:
50 $perl_scalar = JSON->decode($json_text)