JSON::Syck(3)
π JSON::Syck(3) β bestie edition
okay so. JSON::Syck is one of those modules from the perl section of the manual (perl manpage, User Contributed Perl Documentation, if you're keeping track) and honestly? she's a legacy icon. she's fast, she's tiny, and she wants you to know she's probably not the one you should be using anymore. no cap. let's get into it π
β¨ NAME β¨
JSON::Syck β JSON is YAML (but consider using JSON::XS instead!) π«Ά
πΈ SYNOPSIS πΈ
use JSON::Syck; # no exports by default
my $data = JSON::Syck::Load($json);
my $json = JSON::Syck::Dump($data);
# $file can be an IO object, or a filename
my $data = JSON::Syck::LoadFile($file);
JSON::Syck::DumpFile($file, $data);
# Dump into a pre-existing buffer
my $json;
JSON::Syck::DumpInto(\$json, $data);
so like, use JSON::Syck; gives you no exports by default β you're writing out the full names, main character energy, no shortcuts. and yes $file can be an IO object or a filename, pick your fighter β¨
π¦ DESCRIPTION π¦
JSON::Syck is a syck implementation of JSON parsing and generation β she's out here doing both directions, serving versatility π
Because JSON is YAML (proof: http://redhanded.hobix.com/inspect/yamlIsJson.html), leaning on syck means you get a fast and memory-efficient parser and dumper for JSON data representation. literally built different.
However β and this is the part where I hold your hand β a newer module, JSON::XS, has since emerged. She is more flexible, more efficient and more robust, so please consider using her instead of this module. I'm not saying this module is bad, I'm saying the sequel ate π
π₯ DIFFERENCE WITH JSON π₯
so you might be wondering, bestie, what's the difference between the JSON module and this one. real question. love that for you.
Since JSON is a pure-perl module and JSON::Syck is based on libsyck, JSON::Syck is supposed to be very fast and memory efficient. receipts? chansen's benchmark table lives at http://idisk.mac.com/christian.hansen/Public/perl/serialize.pl β go look, I'll wait.
JSON.pm comes with dozens of ways to do the same thing and lots of options, while JSON::Syck doesn't. There's only Load and Dump. that's it. that's the whole menu. minimalism queen π
Oh, and JSON::Syck doesn't use camelCase method names :-) (this is shade, and it is deserved)
β REFERENCES β
π SCALAR REFERENCE
For now, when you pass a scalar reference to JSON::Syck, it dereferences to get the actual scalar value. cute, right?
JSON::Syck raises an exception when you pass in circular references β she's not doing that today, not on her watch π
If you want to serialize self referencing stuff, you should use YAML, which supports it. different tool, different vibe.
π SUBROUTINE REFERENCE
When you pass a subroutine reference, JSON::Syck dumps it as null. code? who? never met her. she's a ghost.
π UTF-8 FLAGS π
By default this module doesn't touch any of the utf-8 flags set in strings, and assumes UTF-8 bytes to be passed and emit. hands off, no notes.
However, when you set $JSON::Syck::ImplicitUnicode to 1, this module properly decodes UTF-8 binaries and sets the UTF-8 flag everywhere, as in:
JSON (UTF-8 bytes) => Perl (UTF-8 flagged)
JSON (UTF-8 flagged) => Perl (UTF-8 flagged)
Perl (UTF-8 bytes) => JSON (UTF-8 flagged)
Perl (UTF-8 flagged) => JSON (UTF-8 flagged)
iconic table behavior, honestly.
By default, JSON::Syck::Dump will only transverse up to 512 levels of a datastructure in order to avoid an infinite loop when it is presented with a circular reference. safety first, bestie π§
However, you can set $JSON::Syck::MaxDepth to a larger value if you have very complex structures. go off, build your deep-ass tree.
Unfortunately, there's no implicit way to dump a Perl UTF-8 flagged data structure to utf-8 encoded JSON. To do this, simply use the Encode module, e.g.:
use Encode;
use JSON::Syck qw(Dump);
my $json = encode_utf8( Dump($data) );
Alternatively you can use Encode::JavaScript::UCS to encode Unicode strings as in %uXXXX form. slay:
use Encode;
use Encode::JavaScript::UCS;
use JSON::Syck qw(Dump);
my $json_unicode_escaped = encode( 'JavaScript-UCS', Dump($data) );
π QUOTING π
According to the JSON specification, all JSON strings are to be double-quoted. that's the law π
However, when embedding JavaScript in HTML attributes, it may be more convenient to use single quotes. context matters!
Set $JSON::Syck::SingleQuote to 1 and it will make both Dump and Load expect single-quoted string literals. flip the switch, change the whole fit π
π BUGS π
- Dumping into tied (or other magic variables) with
DumpIntomight not work properly in all cases. like, sometimes. sometimes not. chaos. - When dumping with
DumpFile, the spacing differs fromDump(extra spaces after colons and a trailing newline) becauseDumpFileuses the C-level serializer directly. same data, different formatting, don't come for her π
π SEE ALSO π
JSON::XS, YAML::Syck
(the first one is the upgrade, the second one is the cousin. iykyk)
π«Ά AUTHORS π«Ά
Audrey Tang <cpan@audreyt.org>
Tatsuhiko Miyagawa <miyagawa@gmail.com>
two legends, one module β¨
π COPYRIGHT π
Copyright 2005-2009 by Audrey Tang <cpan@audreyt.org>.
This software is released under the MIT license cited below.
The libsyck code bundled with this library is released by "why the lucky stiff", under a BSD-style license. See the COPYING file for details.
πΈ The "MIT" License πΈ
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ok that's the whole page, bestie. this one shipped as part ofperl v5.42.0, dated2026-07-14, and she's still out here doing her little syck thing. mwah π
π¦ where this page comes from
- opensuse-leap 16.0: perl-YAML-Syck 1.470.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: perl-YAML-Syck 1.470.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: perl-YAML-Syck 1.470.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: perl-YAML-Syck 1.470.0-bp160.1.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms