JSON-XS

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


4.01 Sun Feb 24 05:03:30 CET 2019
	- fix some stack corruption caused mostly when calling methods
          in list context (testcase by Wesley Schwengle).

4.0  Fri Nov 16 00:06:54 CET 2018
	- SECURITY IMPLICATION: this release enables allow_nonref by default
          for compatibility with RFC 7159 and newer. See "old" vs. "new"
          JSON under SECURITY CONSIDERATIONS.
        - reworked the "old" vs. "new" JSON section.
        - add ->boolean_values to provide the values to which booleans
          decode (requested by Aristotle Pagaltzis).
        - decode would wrongly accept ASCII NUL characters instead of
          reporting them as trailing garbage.
        - work around what smells like a perl bug w.r.t. exceptions
          thrown in callbacks.
        - incremental parser now more or less respects allow_nonref.
	- json_xs json-pretty now enables canonical mode.
        - add documentation section about I-JSON.
        - minor documentation fixes/updates.

README  view on Meta::CPAN

        the object into a nonstandard tagged JSON value (that JSON decoders
        cannot decode).

        It also causes "decode" to parse such tagged JSON values and
        deserialise them via a call to the "THAW" method.

        If $enable is false (the default), then "encode" will not consider
        this type of conversion, and tagged JSON values will cause a parse
        error in "decode", as if tags were not part of the grammar.

    $json->boolean_values ([$false, $true])
    ($false, $true) = $json->get_boolean_values
        By default, JSON booleans will be decoded as overloaded
        $Types::Serialiser::false and $Types::Serialiser::true objects.

        With this method you can specify your own boolean values for
        decoding - on decode, JSON "false" will be decoded as a copy of
        $false, and JSON "true" will be decoded as $true ("copy" here is the
        same thing as assigning a value to another variable, i.e. "$copy =
        $false").

        Calling this method without any arguments will reset the booleans to
        their default values.

        "get_boolean_values" will return both $false and $true values, or
        the empty list when they are set to the default.

    $json = $json->filter_json_object ([$coderef->($hashref)])
        When $coderef is specified, it will be called from "decode" each
        time it decodes a JSON object. The only argument is a reference to
        the newly-created hash. If the code reference returns a single
        scalar (which need not be a reference), this value (or rather a copy
        of it) is inserted into the deserialised data structure. If it
        returns an empty list (NOTE: *not* "undef", which is a valid
        scalar), the original deserialised hash will be inserted. This

XS.pm  view on Meta::CPAN

the object's class. If found, it will be used to serialise the object into
a nonstandard tagged JSON value (that JSON decoders cannot decode).

It also causes C<decode> to parse such tagged JSON values and deserialise
them via a call to the C<THAW> method.

If C<$enable> is false (the default), then C<encode> will not consider
this type of conversion, and tagged JSON values will cause a parse error
in C<decode>, as if tags were not part of the grammar.

=item $json->boolean_values ([$false, $true])

=item ($false,  $true) = $json->get_boolean_values

By default, JSON booleans will be decoded as overloaded
C<$Types::Serialiser::false> and C<$Types::Serialiser::true> objects.

With this method you can specify your own boolean values for decoding -
on decode, JSON C<false> will be decoded as a copy of C<$false>, and JSON
C<true> will be decoded as C<$true> ("copy" here is the same thing as
assigning a value to another variable, i.e. C<$copy = $false>).

Calling this method without any arguments will reset the booleans
to their default values.

C<get_boolean_values> will return both C<$false> and C<$true> values, or
the empty list when they are set to the default.

=item $json = $json->filter_json_object ([$coderef->($hashref)])

When C<$coderef> is specified, it will be called from C<decode> each
time it decodes a JSON object. The only argument is a reference to
the newly-created hash. If the code reference returns a single scalar
(which need not be a reference), this value (or rather a copy of it) is
inserted into the deserialised data structure. If it returns an empty
list (NOTE: I<not> C<undef>, which is a valid scalar), the original

XS.xs  view on Meta::CPAN

{
	SV *pv = NEWSV (0, sizeof (JSON));
        SvPOK_only (pv);
        json_init ((JSON *)SvPVX (pv));
        XPUSHs (sv_2mortal (sv_bless (
           newRV_noinc (pv),
           strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1)
        )));
}

void boolean_values (JSON *self, SV *v_false = 0, SV *v_true = 0)
	PPCODE:
	self->v_false = newSVsv (v_false);
	self->v_true  = newSVsv (v_true);
        XPUSHs (ST (0));

void get_boolean_values (JSON *self)
	PPCODE:
        if (self->v_false && self->v_true)
	  {
            EXTEND (SP, 2);
            PUSHs (self->v_false);
            PUSHs (self->v_true);
          }

void ascii (JSON *self, int enable = 1)
	ALIAS:



( run in 0.247 second using v1.01-cache-2.11-cpan-9ff20fc0ed8 )