Description | manuals and libraries |
Kernel::System::JSON - the JSON wrapper lib
Functions for encoding perl data structures to JSON.
Implicitly turns on key sorting for Encode() method. Useful when the actual call of the method cannot be influenced, but predictable result is still expected (i.e. in the unit tests).
$Kernel::System::JSON::SortKeys = 1;
Implicitly turns on pretty print for the Encode() method. Useful when the actual call of the method cannot be influenced, but predictable result is still expected (i.e. in the unit tests).
$Kernel::System::JSON::Pretty = 1;
create a JSON object. Do not use it directly, instead use:
my $JSONObject = $Kernel::OM->Get('Kernel::System::JSON');
Encode a perl data structure to a JSON string.
my $JSONString = $JSONObject->Encode(
Data => $Data,
SortKeys => 1, # (optional) (0|1) default 0, to sort the keys of the json data
Pretty => 1, # (optional) (0|1) default 0, to pretty print
);
Decode a JSON string to a perl data structure.
my $PerlStructureScalar = $JSONObject->Decode(
Data => $JSONString,
);
returns a constant that can be mapped to a boolean true value in JSON rather than a string with "true".
my $TrueConstant = $JSONObject->True();
my $TrueJS = $JSONObject->Encode(
Data => $TrueConstant,
);
This will return the string 'true'. If you pass the perl string 'true' to JSON, it will return '"true"' as a JavaScript string instead.
like True()
, but for a false boolean value.