27 Jan 2020 22:19:52 UTC
- Distribution: YAML-Syck
- Module version: 1.31
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (26)
- Testers (2565 / 39 / 0)
- KwaliteeBus factor: 3
- % Coverage
- License: mit
- Perl: v5.6.0
- Download (136.79KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:10 non-PAUSE users
- DIFFERENCE WITH JSON
- UTF-8 FLAGS
- SEE ALSO
JSON::Syck - JSON is YAML (but consider using JSON::XS instead!)
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);
JSON::Syck is a syck implementation of JSON parsing and generation. Because JSON is YAML (http://redhanded.hobix.com/inspect/yamlIsJson.html), using syck gives you a fast and memory-efficient parser and dumper for JSON data representation.
However, a newer module JSON::XS, has since emerged. It is more flexible, efficient and robust, so please consider using it instead of this module.
You might want to know the difference between the JSON module and this one.
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. See chansen's benchmark table at http://idisk.mac.com/christian.hansen/Public/perl/serialize.pl
JSON.pm comes with dozens of ways to do the same thing and lots of options, while JSON::Syck doesn't. There's only
Oh, and JSON::Syck doesn't use camelCase method names :-)
For now, when you pass a scalar reference to JSON::Syck, it dereferences to get the actual scalar value.
JSON::Syck raises an exception when you pass in circular references.
If you want to serialize self referencing stuff, you should use YAML which supports it.
When you pass subroutine reference, JSON::Syck dumps it as null.
By default this module doesn't touch any of utf-8 flags set in strings, and assumes UTF-8 bytes to be passed and emit.
However, when you set
$JSON::Syck::ImplicitUnicodeto 1, this module properly decodes UTF-8 binaries and sets 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)
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 an circular reference.
However, you set
$JSON::Syck::MaxLevelsto a larger value if you have very complex structures.
Unfortunately, there's no implicit way to dump Perl UTF-8 flagged data structure to utf-8 encoded JSON. To do this, simply use Encode module, e.g.:
use Encode; use JSON::Syck qw(Dump); my $json = encode_utf8( Dump($data) );
$JSON::Syck::SingleQuoteto 1 will make both
Loadexpect single-quoted string literals.
Dumping into tied (or other magic variables) with
DumpIntomight not work properly in all cases.
When dumping with
DumpFile, some spacing might be wrong and
$JSON::Syck::SingleQuotemight be handled incorrectly.
Audrey Tang <email@example.com>
Tatsuhiko Miyagawa <firstname.lastname@example.org>
Copyright 2005-2009 by Audrey Tang <email@example.com>.
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.
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.
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|