info > Cpanel::JSON::XS

XS(3pm) User Contributed Perl Documentation XS(3pm)

๐Ÿ“› NAME

Cpanel::JSON::XS - cPanel fork of JSON::XS, fast and correct serializing

๐Ÿš€ Quick Reference

Use CaseCommandDescription
Encode Perl to JSON (UTF-8)encode_json $perl_hash_or_arrayref๐Ÿ”„ Converts Perl data structure to UTF-8 JSON string
Decode JSON to Perldecode_json $utf8_encoded_json_text๐Ÿ” Parses UTF-8 JSON string to Perl data structure
OO encode with options$coder = Cpanel::JSON::XS->new->ascii->pretty->allow_nonref; $coder->encode($perl_scalar)โš™๏ธ Configure encoding style (ASCII, pretty, etc.)
OO decode$coder->decode($unicode_json_text)๐Ÿ“ฅ Decode JSON with configured options
Use JSON::MaybeXSuse JSON::MaybeXS;๐Ÿ”„ Automatically uses Cpanel::JSON::XS if available
Check booleanCpanel::JSON::XS::is_bool($scalar)โœ… Returns true if scalar is JSON true/false

๐Ÿ“‹ SYNOPSIS

use Cpanel::JSON::XS;

# exported functions, they croak on error
# and expect/generate UTF-8

$utf8_encoded_json_text = encode_json $perl_hash_or_arrayref;
$perl_hash_or_arrayref  = decode_json $utf8_encoded_json_text;

# OO-interface

$coder = Cpanel::JSON::XS->new->ascii->pretty->allow_nonref;
$pretty_printed_unencoded = $coder->encode ($perl_scalar);
$perl_scalar = $coder->decode ($unicode_json_text);

# Note that 5.6 misses most smart utf8 and encoding functionalities
# of newer releases.

# Note that L<JSON::MaybeXS> will automatically use Cpanel::JSON::XS
# if available, at virtually no speed overhead either, so you should
# be able to just:

use JSON::MaybeXS;

# and do the same things, except that you have a pure-perl fallback now.

Note that this module will be replaced by a new JSON::Safe module soon,
with the same API just guaranteed safe defaults.

๐Ÿ“– DESCRIPTION

This module converts Perl data structures to JSON and vice versa. Its primary goal is to be correct and its secondary goal is to be fast. To reach the latter goal it was written in C.

As this is the n-th-something JSON module on CPAN, what was the reason to write yet another JSON module? While it seems there are many JSON modules, none of them correctly handle all corner cases, and in most cases their maintainers are unresponsive, gone missing, or not listening to bug reports for other reasons.

See below for the cPanel fork.

See MAPPING, below, on how Cpanel::JSON::XS maps perl values to JSON values and vice versa.

โœจ FEATURES

๐Ÿ”„ cPanel fork

Since the original author MLEHMANN has no public bugtracker, this cPanel fork sits now on github.

src repo: https://github.com/rurban/Cpanel-JSON-XS original: http://cvs.schmorp.de/JSON-XS/

RT: https://github.com/rurban/Cpanel-JSON-XS/issues or https://rt.cpan.org/Public/Dist/Display.html?Queue=Cpanel-JSON-XS

Changes to JSON::XS

โš™๏ธ FUNCTIONAL INTERFACE

The following convenience methods are provided by this module. They are exported by default:

$json_text = encode_json $perl_scalar, [json_type]
Converts the given Perl data structure to a UTF-8 encoded, binary string (that is, the string contains octets only). Croaks on error.

This function call is functionally identical to:

   $json_text = Cpanel::JSON::XS->new->utf8->encode ($perl_scalar, $json_type)

Except being faster.

For the type argument see Cpanel::JSON::XS::Type.

$perl_scalar = decode_json $json_text [, $allow_nonref [, my $json_type ] ]
The opposite of "encode_json": expects an UTF-8 (binary) string of an json reference and tries to parse that as an UTF-8 encoded JSON text, returning the resulting reference. Croaks on error.

This function call is functionally identical to:

   $perl_scalar = Cpanel::JSON::XS->new->utf8->decode ($json_text, $json_type)

except being faster.

If the new 2nd optional $allow_nonref argument is set and not false, the "allow_nonref" option will be set.

For the 3rd optional type argument see Cpanel::JSON::XS::Type.

$is_boolean = Cpanel::JSON::XS::is_bool $scalar
Returns true if the passed scalar represents either JSON::PP::true or JSON::PP::false, two constants that act like 1 and 0, respectively and are used to represent JSON "true" and "false" values in Perl.

โš ๏ธ DEPRECATED FUNCTIONS

๐ŸŒ A FEW NOTES ON UNICODE AND PERL

Since this often leads to confusion, here are a few very clear words on how Unicode works in Perl, modulo bugs.

  1. Perl strings can store characters with ordinal values > 255.
  2. Perl does not associate an encoding with your strings.
  3. The internal utf-8 flag has no meaning with regards to the encoding of your string.
  4. A "Unicode String" is simply a string where each character can be validly interpreted as a Unicode code point.
  5. A string containing "high" (> 255) character values is not a UTF-8 string.
  6. Unicode noncharacters only warn, as in core.
  7. Raw non-Unicode characters above U+10FFFF are disallowed.

I hope this helps :)

๐Ÿ”ง OBJECT-ORIENTED INTERFACE

The object oriented interface lets you configure your own encoding or decoding style, within the limits of supported formats.

$json = new Cpanel::JSON::XS
Creates a new JSON object that can be used to de/encode JSON strings. All boolean flags described below are by default disabled.

The mutators for flags all return the JSON object again and thus calls can be chained:

   my $json = Cpanel::JSON::XS->new->utf8->space_after->encode ({a => [1,2]})
   => {"a": [1, 2]}

$json = $json->ascii ([$enable])
$enabled = $json->get_ascii
If $enable is true (or missing), then the "encode" method will not generate characters outside the code range 0..127 (which is ASCII). Any Unicode characters outside that range will be escaped using either a single "\uXXXX" (BMP characters) or a double "\uHHHH\uLLLLL" escape sequence, as per RFC4627.

$json = $json->latin1 ([$enable])
$enabled = $json->get_latin1
If $enable is true (or missing), then the "encode" method will encode the resulting JSON text as latin1 (or ISO-8859-1), escaping any characters outside the code range 0..255.

$json = $json->binary ([$enable])
$enabled = $json = $json->get_binary
If the $enable argument is true (or missing), then the "encode" method will not try to detect an UTF-8 encoding in any JSON string, it will strictly interpret it as byte sequence. The result might contain new "\xNN" sequences, which is unparsable JSON.

$json = $json->utf8 ([$enable])
$enabled = $json->get_utf8
If $enable is true (or missing), then the "encode" method will encode the JSON result into UTF-8, as required by many protocols, while the "decode" method expects to be handled an UTF-8-encoded string.

$json = $json->pretty ([$enable])
This enables (or disables) all of the "indent", "space_before" and "space_after" (and in the future possibly more) flags in one call to generate the most readable (or most compact) form possible.

$json = $json->indent ([$enable])
$enabled = $json->get_indent
If $enable is true (or missing), then the "encode" method will use a multiline format as output.

$json = $json->indent_length([$number_of_spaces])
$length = $json->get_indent_length()
Set the indent length (default 3).

$json = $json->space_before ([$enable])
$enabled = $json->get_space_before
If $enable is true (or missing), then the "encode" method will add an extra optional space before the ":" separating keys from values in JSON objects.

$json = $json->space_after ([$enable])
$enabled = $json->get_space_after
If $enable is true (or missing), then the "encode" method will add an extra optional space after the ":" separating keys from values in JSON objects and extra whitespace after the "," separating key-value pairs and array members.

$json = $json->relaxed ([$enable])
$enabled = $json->get_relaxed
If $enable is true (or missing), then "decode" will accept some extensions to normal JSON syntax (see below).

$json = $json->canonical ([$enable])
$enabled = $json->get_canonical
If $enable is true (or missing), then the "encode" method will output JSON objects by sorting their keys.

$json = $json->sort_by (undef, 0, 1 or a block)
This currently only (un)sets the "canonical" option, and ignores custom sort blocks.

$json = $json->escape_slash ([$enable])
$enabled = $json->get_escape_slash
If $enable is true (or missing), then "encode" will escape slashes, "\/".

$json = $json->unblessed_bool ([$enable])
$enabled = $json->get_unblessed_bool
If $enable is true (or missing), then "decode" will return Perl non-object boolean variables (1 and 0) for JSON booleans ("true" and "false").

$json = $json->allow_singlequote ([$enable])
$enabled = $json->get_allow_singlequote
If $enable is true (or missing), then "decode" will accept JSON strings quoted by single quotations that are invalid JSON format.

$json = $json->allow_barekey ([$enable])
$enabled = $json->get_allow_barekey
If $enable is true (or missing), then "decode" will accept bare keys of JSON object that are invalid JSON format.

$json = $json->allow_bignum ([$enable])
$enabled = $json->get_allow_bignum
If $enable is true (or missing), then "decode" will convert the big integer Perl cannot handle as integer into a Math::BigInt object and convert a floating number (any) into a Math::BigFloat.

$json = $json->allow_bigint ([$enable])
This option is obsolete and replaced by allow_bignum.

$json = $json->allow_nonref ([$enable])
$enabled = $json->get_allow_nonref
If $enable is true (or missing), then the "encode" method can convert a non-reference into its corresponding string, number or null JSON value.

$json = $json->allow_unknown ([$enable])
$enabled = $json->get_allow_unknown
If $enable is true (or missing), then "encode" will not throw an exception when it encounters values it cannot represent in JSON (for example, filehandles) but instead will encode a JSON "null" value.

$json = $json->allow_stringify ([$enable])
$enabled = $json->get_allow_stringify
If $enable is true (or missing), then "encode" will stringify the non-object perl value or reference.

$json = $json->require_types ([$enable])
$enable = $json->get_require_types
If $enable is true (or missing), then "encode" will require either enabled "type_all_string" or second argument with supplied JSON types.

$json = $json->type_all_string ([$enable])
$enable = $json->get_type_all_string
If $enable is true (or missing), then "encode" will always produce stable deterministic JSON string types in resulted output.

$json = $json->allow_dupkeys ([$enable])
$enabled = $json->get_allow_dupkeys
If $enable is true (or missing), then the "decode" method will not die when it encounters duplicate keys in a hash.

$json = $json->allow_blessed ([$enable])
$enabled = $json->get_allow_blessed
If $enable is true (or missing), then the "encode" method will not barf when it encounters a blessed reference.

$json = $json->convert_blessed ([$enable])
$enabled = $json->get_convert_blessed
If $enable is true (or missing), then "encode", upon encountering a blessed object, will check for the availability of the "TO_JSON" method on the object's class.

$json = $json->allow_tags ([$enable])
$enabled = $json->get_allow_tags
See "OBJECT SERIALIZATION" for details.

$json = $json->filter_json_object ([$coderef->($hashref)])
When $coderef is specified, it will be called from "decode" each time it decodes a JSON object.

$json = $json->filter_json_single_key_object ($key [=> $coderef->($value)])
Works remotely similar to "filter_json_object", but is only called for JSON objects having a single key named $key.

$json = $json->shrink ([$enable])
$enabled = $json->get_shrink
Perl usually over-allocates memory a bit when allocating space for strings. This flag optionally resizes strings generated by either "encode" or "decode" to their minimum size possible.

$json = $json->max_depth ([$maximum_nesting_depth])
$max_depth = $json->get_max_depth
Sets the maximum nesting level (default 512) accepted while encoding or decoding.

$json = $json->max_size ([$maximum_string_size])
$max_size = $json->get_max_size
Set the maximum length a JSON text may have (in bytes) where decoding is being attempted.

$json->stringify_infnan ([$infnan_mode = 1])
$infnan_mode = $json->get_stringify_infnan
Get or set how Cpanel::JSON::XS encodes "inf", "-inf" or "nan" for numeric values.

$json_text = $json->encode ($perl_scalar, $json_type)
Converts the given Perl data structure (a simple scalar or a reference to a hash or array) to its JSON representation.

$perl_scalar = $json->decode ($json_text, my $json_type)
The opposite of "encode": expects a JSON text and tries to parse it, returning the resulting simple scalar or reference.

($perl_scalar, $characters) = $json->decode_prefix ($json_text)
This works like the "decode" method, but instead of raising an exception when there is trailing garbage after the first JSON object, it will silently stop parsing there and return the number of characters consumed so far.

$json->to_json ($perl_hash_or_arrayref)
Deprecated method for perl 5.8 and newer. Use encode_json instead.

$json->from_json ($utf8_encoded_json_text)
Deprecated method for perl 5.8 and newer. Use decode_json instead.

๐Ÿ“ˆ INCREMENTAL PARSING

In some cases, there is the need for incremental parsing of JSON texts. While this module always has to keep both JSON text and resulting Perl data structure in memory at one time, it does allow you to parse a JSON stream incrementally.

[void, scalar or list context] = $json->incr_parse ([$string])
This is the central parsing function. It can both append new text and extract objects from the stream accumulated so far.

$lvalue_string = $json->incr_text (>5.8 only)
This method returns the currently stored JSON fragment as an lvalue, that is, you can manipulate it.

$json->incr_skip
This will reset the state of the incremental parser and will remove the parsed text from the input buffer so far.

$json->incr_reset
This completely resets the incremental parser.

โš ๏ธ LIMITATIONS

All options that affect decoding are supported, except "allow_nonref".

๐Ÿ“ EXAMPLES

Some examples will make all this clearer. First, a simple example that works similarly to "decode_prefix":

my $text = "[1,2,3] hello";

my $json = new Cpanel::JSON::XS;

my $obj = $json->incr_parse ($text)
   or die "expected JSON object or array at beginning of string";

my $tail = $json->incr_text;
# $tail now contains " hello"

Now for a more complicated example: Imagine a hypothetical protocol where you read some requests from a TCP stream.

my $json = new Cpanel::JSON::XS;

# read some data from the socket
while (sysread $socket, my $buf, 4096) {

   # split and decode as many requests as possible
   for my $request ($json->incr_parse ($buf)) {
      # act on the $request
   }
}

Another complicated example: Assume you have a string with JSON objects or arrays, all separated by (optional) comma characters.

my $text = "[1],[2], [3]";
my $json = new Cpanel::JSON::XS;

# void context, so no parsing done
$json->incr_parse ($text);

# now extract as many objects as possible. note the
# use of scalar context so incr_text can be called.
while (my $obj = $json->incr_parse) {
   # do something with $obj

   # now skip the optional comma
   $json->incr_text =~ s/^ \s* , //x;
}

Now lets go for a very complex example: Assume that you have a gigantic JSON array-of-objects, many gigabytes in size.

my $json = new Cpanel::JSON::XS;

# open the monster
open my $fh, "<bigfile.json"
   or die "bigfile: $!";

# first parse the initial "["
for (;;) {
   sysread $fh, my $buf, 65536
      or die "read error: $!";
   $json->incr_parse ($buf); # void context, so no parsing

   last if $json->incr_text =~ s/^ \s* \[ //x;
}

# now we have the skipped the initial "[", so continue
# parsing all the elements.
for (;;) {
   for (;;) {
      if (my $obj = $json->incr_parse) {
         # do something with $obj
         last;
      }
      sysread $fh, my $buf, 65536
         or die "read error: $!";
      $json->incr_parse ($buf);
   }

   for (;;) {
      $json->incr_text =~ s/^\s*//;

      if ($json->incr_text =~ s/^\]//) {
         print "finished.\n";
         exit;
      }

      if ($json->incr_text =~ s/^,//) {
         last;
      }

      if (length $json->incr_text) {
         die "parse error near ", $json->incr_text;
      }

      sysread $fh, my $buf, 65536
         or die "read error: $!";
      $json->incr_parse ($buf);
   }
}

This is a complex example, but most of the complexity comes from the fact that we are trying to be correct.

๐Ÿงพ BOM

Detect all unicode Byte Order Marks on decode. Which are UTF-8, UTF-16LE, UTF-16BE, UTF-32LE and UTF-32BE.

Warning: With perls older than 5.20 you need load the Encode module before loading a multibyte BOM, i.e. >= UTF-16.

See https://tools.ietf.org/html/rfc7159#section-8.1 "JSON text SHALL be encoded in UTF-8, UTF-16, or UTF-32."

Beware that Cpanel::JSON::XS is currently the only JSON module which does accept and decode a BOM.

The latest JSON spec https://www.greenbytes.de/tech/webdav/rfc8259.html#character.encoding forbid the usage of UTF-16 or UTF-32, the character encoding is UTF-8. Thus in subsequent updates BOM's of UTF-16 or UTF-32 will throw an error.

๐Ÿ”„ MAPPING

This section describes how Cpanel::JSON::XS maps Perl values to JSON values and vice versa.

๐Ÿ“ฅ JSON โ†’ PERL

๐Ÿ“ค PERL โ†’ JSON

๐Ÿ”— OBJECT SERIALIZATION

As JSON cannot directly represent Perl objects, you have to choose between a pure JSON representation (without the ability to deserialize the object automatically again), and a nonstandard extension to the JSON syntax, tagged values.

SERIALIZATION

What happens when Cpanel::JSON::XS encounters a Perl object depends on the "allow_blessed", "convert_blessed" and "allow_tags" settings, which are used in this order:

  1. allow_tags is enabled and the object has a FREEZE method.
  2. convert_blessed is enabled and the object has a TO_JSON method.
  3. convert_blessed is enabled and the object has a stringification overload.
  4. allow_blessed is enabled.
  5. none of the above โ€“ throws an exception.

DESERIALIZATION

For deserialization there are only two cases to consider: either nonstandard tagging was used, in which case "allow_tags" decides, or objects cannot be automatically be deserialized, in which case you can use postprocessing or the "filter_json_object" or "filter_json_single_key_object" callbacks.

๐Ÿณ๏ธ ENCODING/CODESET FLAG NOTES

The interested reader might have seen a number of flags that signify encodings or codesets - "utf8", "latin1", "binary" and "ascii". Here is a short comparison:

๐ŸŒ JSON and ECMAscript

JSON syntax is based on how literals are represented in javascript. However, JSON is not a subset (and also not a superset of course) of ECMAscript.

If you want to use javascript's "eval" function to "parse" JSON, you might run into parse errors for valid JSON texts.

The right fix for this is to use a proper JSON parser in your javascript programs, and not rely on "eval".

If this is not an option, you can encode to ASCII-only JSON:

use Cpanel::JSON::XS;

print Cpanel::JSON::XS->new->ascii->encode ([chr 0x2028]);

Unicode non-characters between U+FFFD and U+10FFFF are decoded either to the recommended U+FFFD REPLACEMENT CHARACTER or left as is in binary or relaxed mode.

๐Ÿ“ JSON and YAML

You often hear that JSON is a subset of YAML. In general, there is no way to configure JSON::XS to output a data structure as valid YAML that works in all cases.

my $to_yaml = Cpanel::JSON::XS->new->utf8->space_after (1);
my $yaml = $to_yaml->encode ($ref) . "\n";

โšก SPEED

It seems that JSON::XS is surprisingly fast, as shown in the following tables.

First comes a comparison between various modules using a very short single-line JSON string:

   module        |     encode |     decode |
   --------------|------------|------------|
   JSON::DWIW/DS |  86302.551 | 102300.098 |
   JSON::DWIW/FJ |  86302.551 |  75983.768 |
   JSON::PP      |  15827.562 |   6638.658 |
   JSON::Syck    |  63358.066 |  47662.545 |
   JSON::XS      | 511500.488 | 511500.488 |
   JSON::XS/2    | 291271.111 | 388361.481 |
   JSON::XS/3    | 361577.931 | 361577.931 |
   Storable      |  66788.280 | 265462.278 |
   --------------+------------+------------+

Using a longer test string (roughly 18KB):

   module        |     encode |     decode |
   --------------|------------|------------|
   JSON::DWIW/DS |   1647.927 |   2673.916 |
   JSON::DWIW/FJ |   1630.249 |   2596.128 |
   JSON::PP      |    400.640 |     62.311 |
   JSON::Syck    |   1481.040 |   1524.869 |
   JSON::XS      |  20661.596 |   9541.183 |
   JSON::XS/2    |  10683.403 |   9416.938 |
   JSON::XS/3    |  20661.596 |   9400.054 |
   Storable      |  19765.806 |  10000.725 |
   --------------+------------+------------+

For updated graphs see https://github.com/Sereal/Sereal/wiki/Sereal-Comparison-Graphs

๐Ÿค INTEROP with JSON and JSON::XS and other JSON modules

As long as you only serialize data that can be directly expressed in JSON, Cpanel::JSON::XS is incapable of generating invalid JSON output. Cpanel::JSON::XS is currently the only known JSON decoder which passes all http://seriot.ch/parsing_json.html tests, while being the fastest also.

When decoding, JSON::XS is strict by default.

JSON-XS-3.01 broke interoperability with JSON-2.90 with booleans.

Cpanel::JSON::XS needs to know the JSON and JSON::XS versions to be able work with those objects.

true/false overloading and boolean representations are supported.

I cannot think of any reason to still use JSON::XS anymore.

๐Ÿท๏ธ TAGGED VALUE SYNTAX AND STANDARD JSON EN/DECODERS

When you use "allow_tags" to use the extended JSON syntax for serialized objects, you can run a regex to replace the tagged syntax by standard JSON arrays.

# if your FREEZE methods return no values, you need this replace first:
$json =~ s/\( \s* (" (?: [^\\":,]+|\\.|::)* ") \s* \) \s* \[\s*\]/[$1]/gx;

# this works for non-empty constructor arg lists:
$json =~ s/\( \s* (" (?: [^\\":,]+|\\.|::)* ") \s* \) \s* \[/[$1,/gx;

Here is an ECMAScript version (same regex):

json = json.replace (/\(\s*("([^\\":,]+|\\.|::)*")\s*\)\s*\[/g, "[$1,");

Since this syntax converts to standard JSON arrays, you can prepend a "magic number" as first array element to reduce chances of a collision.

๐Ÿ“œ RFC7159

Since this module was written, Google has written a new JSON RFC, RFC 7159 (and RFC7158). Unfortunately, this RFC breaks compatibility with both the original JSON specification on www.json.org and RFC4627.

As far as I can see, you can get partial compatibility when parsing by using "->allow_nonref".

I haven't decided yet when to break compatibility with RFC4627 by default (and potentially leave applications insecure) and change the default to follow RFC7159, but application authors are well advised to call "->allow_nonref(0)" even if this is the current default.

๐Ÿ”’ SECURITY CONSIDERATIONS

JSON::XS and Cpanel::JSON::XS are not only fast. JSON is generally the most secure serializing format, because it is the only one besides Data::MessagePack, which does not deserialize objects per default.

It is trivial for any attacker to create such serialized objects in JSON and trick perl into expanding them.

Security relevant overview of serializers regarding deserializing objects by default:

                          Objects   Coderefs  External Data

Data::Dumper      YES       YES       YES
Storable          YES       NO (def)  NO
Sereal            YES       NO        NO
YAML              YES       NO        NO
B::C              YES       YES       YES
B::Bytecode       YES       YES       YES
BSON              YES       YES       NO
JSON::SL          YES       NO        YES
JSON              NO (def)  NO        NO
Data::MessagePack NO        NO        NO
XML               NO        NO        YES

Pickle            YES       YES       YES
PHP Deserialize   YES       NO        NO

When you are using JSON in a protocol, talking to untrusted potentially hostile creatures requires relatively few measures.

First, your JSON decoder should be secure, i.e., should not have any buffer overflows. Obviously, this module should ensure that.

Second, you need to avoid resource-starving attacks. You should limit the size of JSON texts you accept, or make sure then when your resources run out, that's just fine.

Third, Cpanel::JSON::XS recurses using the C stack when decoding objects and arrays. The default nesting limit is set to 512.

Also keep in mind that Cpanel::JSON::XS might leak contents of your Perl data structures in its error messages.

If you are using Cpanel::JSON::XS to return packets to consumption by JavaScript scripts in a browser you should have a look at http://blog.archive.jpsykes.com/47/practical-csrf-and-json-security/ to see whether you are vulnerable to some common attack vectors.

๐Ÿ†š "OLD" VS. "NEW" JSON (RFC 4627 VS. RFC 7159)

TL;DR: Due to security concerns, Cpanel::JSON::XS will not allow scalar data in JSON texts by default - you need to create your own Cpanel::JSON::XS object and enable "allow_nonref":

my $json = JSON::XS->new->allow_nonref;

$text = $json->encode ($data);
$data = $json->decode ($text);

The long version: JSON being an important and supposedly stable format, the IETF standardized it as RFC 4627 in 2006. Unfortunately the inventor of JSON Douglas Crockford unilaterally changed the definition of JSON in javascript. Rather than create a fork, the IETF decided to standardize the new syntax.

The biggest difference between the original JSON and the new JSON is that the new JSON supports scalars at the top-level of a JSON text. This breaks a number of protocols that relied on sending JSON back-to-back, and is a minor security concern.

This module has always allowed these messages as an optional extension, by default disabled. You are advised to check your implementation and/or override the default with "->allow_nonref (0)" to ensure that future versions are safe.

๐Ÿงต THREADS

Cpanel::JSON::XS has proper ithreads support, unlike JSON::XS. If you encounter any bugs with thread support please report them.

From Version 4.00 - 4.19 you couldn't encode true with threads::shared magic.

๐Ÿ› BUGS

While the goal of the Cpanel::JSON::XS module is to be correct, that unfortunately does not mean it's bug-free, only that the author thinks its design is bug-free. If you keep reporting bugs and tests they will be fixed swiftly, though.

Since the JSON::XS author refuses to use a public bugtracker and prefers private emails, we use the tracker at github, so you might want to report any issues twice.

https://github.com/rurban/Cpanel-JSON-XS/issues

๐Ÿ“„ LICENSE

This module is available under the same licences as perl, the Artistic license and the GPL.

๐Ÿ‘€ SEE ALSO

The cpanel_json_xs command line utility for quick experiments.

JSON, JSON::XS, JSON::MaybeXS, Mojo::JSON, Mojo::JSON::MaybeXS, JSON::SL, JSON::DWIW, JSON::YAJL, JSON::Any, Test::JSON, Locale::Wolowitz, https://metacpan.org/search?q=JSON

https://tools.ietf.org/html/rfc7159

https://tools.ietf.org/html/rfc4627

โœ๏ธ AUTHOR

Reini Urban <rurban@cpan.org>

Marc Lehmann <schmorp@schmorp.de>, http://home.schmorp.de/

๐Ÿ› ๏ธ MAINTAINER

Reini Urban <rurban@cpan.org>

perl v5.34.0 2025-09-12 XS(3pm)

Cpanel::JSON::XS
๐Ÿ“› NAME ๐Ÿš€ Quick Reference ๐Ÿ“‹ SYNOPSIS ๐Ÿ“– DESCRIPTION
โœจ FEATURES ๐Ÿ”„ cPanel fork
โš™๏ธ FUNCTIONAL INTERFACE โš ๏ธ DEPRECATED FUNCTIONS ๐ŸŒ A FEW NOTES ON UNICODE AND PERL ๐Ÿ”ง OBJECT-ORIENTED INTERFACE ๐Ÿ“ˆ INCREMENTAL PARSING
โš ๏ธ LIMITATIONS ๐Ÿ“ EXAMPLES
๐Ÿงพ BOM ๐Ÿ”„ MAPPING
๐Ÿ“ฅ JSON โ†’ PERL ๐Ÿ“ค PERL โ†’ JSON ๐Ÿ”— OBJECT SERIALIZATION
๐Ÿณ๏ธ ENCODING/CODESET FLAG NOTES ๐ŸŒ JSON and ECMAscript ๐Ÿ“ JSON and YAML โšก SPEED ๐Ÿค INTEROP with JSON and JSON::XS and other JSON modules ๐Ÿท๏ธ TAGGED VALUE SYNTAX AND STANDARD JSON EN/DECODERS ๐Ÿ“œ RFC7159 ๐Ÿ”’ SECURITY CONSIDERATIONS ๐Ÿ†š "OLD" VS. "NEW" JSON (RFC 4627 VS. RFC 7159) ๐Ÿงต THREADS ๐Ÿ› BUGS ๐Ÿ“„ LICENSE ๐Ÿ‘€ SEE ALSO โœ๏ธ AUTHOR ๐Ÿ› ๏ธ MAINTAINER

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-25 03:01 @216.73.216.179
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!