1Mojo::JSON(3) User Contributed Perl Documentation Mojo::JSON(3)
2
3
4
6 Mojo::JSON - Minimalistic JSON
7
9 use Mojo::JSON;
10
11 my $json = Mojo::JSON->new;
12 my $string = $json->encode({foo => [1, 2], bar => 'hello!'});
13 my $hash = $json->decode('{"foo": [3, -2, 1]}');
14
16 Mojo::JSON is a minimalistic and relaxed implementation of RFC4627.
17
18 It supports normal Perl data types like "Scalar", "Array" and "Hash",
19 but not blessed references.
20
21 [1, -2, 3] -> [1, -2, 3]
22 {"foo": "bar"} -> {foo => 'bar'}
23
24 Literal names will be translated to and from Mojo::JSON constants or a
25 similar native Perl value.
26
27 true -> Mojo::JSON->true
28 false -> Mojo::JSON->false
29 null -> undef
30
31 Decoding UTF-16 (LE/BE) and UTF-32 (LE/BE) will be handled
32 transparently, encoding will only generate UTF-8.
33
35 Mojo::JSON implements the following attributes.
36
37 "error"
38 my $error = $json->error;
39 $json = $json->error('Oops!');
40
41 Parser errors.
42
44 Mojo::JSON inherits all methods from Mojo::Base and implements the
45 following new ones.
46
47 "decode"
48 my $array = $json->decode('[1, 2, 3]');
49 my $hash = $json->decode('{"foo": "bar"}');
50
51 Decode JSON string.
52
53 "encode"
54 my $string = $json->encode({foo => 'bar'});
55
56 Encode Perl structure.
57
58 "false"
59 my $false = Mojo::JSON->false;
60 my $false = $json->false;
61
62 False value, used because Perl has no native equivalent.
63
64 "true"
65 my $true = Mojo::JSON->true;
66 my $true = $json->true;
67
68 True value, used because Perl has no native equivalent.
69
71 Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
72
73
74
75perl v5.12.3 2010-08-12 Mojo::JSON(3)