1JSON::Syck(3) User Contributed Perl Documentation JSON::Syck(3)
2
3
4
6 JSON::Syck - JSON is YAML
7
9 use JSON::Syck;
10
11 my $data = JSON::Syck::Load($json);
12 my $json = JSON::Syck::Dump($data);
13
15 JSON::Syck is a syck implementatoin of JSON parsing and generation.
16 Because JSON is YAML (<http://redhanded.hobix.com/inspect/yamlIsJ‐
17 son.html>), using syck gives you the fastest and most memory efficient
18 parser and dumper for JSON data representation.
19
21 You might want to know the difference between JSON and JSON::Syck.
22
23 Since JSON is a pure-perl module and JSON::Syck is based on libsyck,
24 JSON::Syck is supposed to be very fast and memory efficient. See
25 chansen's benchmark table at <http://idisk.mac.com/chris‐
26 tian.hansen/Public/perl/serialize.pl>
27
28 JSON.pm comes with dozens of ways to do the same thing and lots of
29 options, while JSON::Syck doesn't. There's only "Load" and "Dump".
30
31 Oh, and JSON::Syck doesn't use camelCase method names :-)
32
34 SCALAR REFERNECE
35
36 For now, when you pass a scalar reference to JSON::Syck, it derefer‐
37 ences to get the actual scalar value.
38
39 JSON::Syck raises an exception when you pass in circular references.
40
41 If you want to serialize self refernecing stuff, you should use YAML
42 which supports it.
43
44 SUBROUTINE REFERENCE
45
46 When you pass subroutine reference, JSON::Syck dumps it as null.
47
49 By default this module doesn't touch any of utf-8 flags set in strings,
50 and assumes UTF-8 bytes to be passed and emit.
51
52 However, when you set $JSON::Syck::ImplicitUnicode to 1, this module
53 properly decodes UTF-8 binaries and sets UTF-8 flag everywhere, as in:
54
55 JSON (UTF-8 bytes) => Perl (UTF-8 flagged)
56 JSON (UTF-8 flagged) => Perl (UTF-8 flagged)
57 Perl (UTF-8 bytes) => JSON (UTF-8 flagged)
58 Perl (UTF-8 flagged) => JSON (UTF-8 flagged)
59
60 Unfortunately, there's no implicit way to dump Perl UTF-8 flagged data
61 structure to utf-8 encoded JSON. To do this, simply use Encode module,
62 e.g.:
63
64 use Encode;
65 use JSON::Syck qw(Dump);
66
67 my $json = encode_utf8( Dump($data) );
68
69 Alternatively you can use Encode::JavaScript::UCS to encode Unicode
70 strings as in %uXXXX form.
71
72 use Encode;
73 use Encode::JavaScript::UCS;
74 use JSON::Syck qw(Dump);
75
76 my $json_unicode_escaped = encode( 'JavaScript-UCS', Dump($data) );
77
79 According to the JSON specification, all JSON strings are to be dou‐
80 ble-quoted. However, when embedding JavaScript in HTML attributes, it
81 may be more convenient to use single quotes.
82
83 Set $JSON::Syck::SingleQuote to 1 will make both "Dump" and "Load"
84 expect single-quoted string literals.
85
87 Audrey Tang <cpan@audreyt.org>
88
89 Tatsuhiko Miyagawa <miyagawa@gmail.com>
90
92 Copyright 2005, 2006, 2007 by Audrey Tang <cpan@audreyt.org>.
93
94 This software is released under the MIT license cited below.
95
96 The libsyck code bundled with this library is released by "why the
97 lucky stiff", under a BSD-style license. See the COPYING file for
98 details.
99
100 The "MIT" License
101
102 Permission is hereby granted, free of charge, to any person obtaining a
103 copy of this software and associated documentation files (the "Soft‐
104 ware"), to deal in the Software without restriction, including without
105 limitation the rights to use, copy, modify, merge, publish, distribute,
106 sublicense, and/or sell copies of the Software, and to permit persons
107 to whom the Software is furnished to do so, subject to the following
108 conditions:
109
110 The above copyright notice and this permission notice shall be included
111 in all copies or substantial portions of the Software.
112
113 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
114 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MER‐
115 CHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
116 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
117 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
118 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT‐
119 WARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
120
121
122
123perl v5.8.8 2007-01-25 JSON::Syck(3)