Closed yahermann closed 3 years ago
You are misunderstanding the point of [ ]
in this doc. This indicates that the values inside the brackets can be omitted. Note that the doc says Calling this method without any arguments will reset the booleans to their default values.
See also other methods such as $json = $json->ascii ([$enable])
and $json = $json->filter_json_single_key_object ($key [=> $coderef->($value)])
and their actual usage.
The mutation of $json object is a compatibility bug in JSON::PP. Thanks for spotting this. I'll file this issue in its tracker. Closing here.
Ah. In that case I suggest using something other than [ ]
to indicate optional settings. As I'm sure you know, [ $false, $true ]
is Perl syntax for an arrayref, very commonly used as a parameter in a function call, therefore easily misunderstood.
In my case, I couldn't get boolean_values
to work because I was setting as $json->boolean_values([ 0, 1 ]);
. It took digging into the source code to figure out why.
Doc states:
$json->boolean_values([ $false, $true ]);
But this is incorrect. Correct call is:
$json->boolean_values( $false, $true );
I also suggest including some indication the above call mutates
$json
. This is to differentiate from other methods that follow$json = $json->some_method( ... );
. In fact,$json = $json->boolean_values( ... );
returns the values set, therefore destroying$json
.Test: