BASE . LOG,
'log_file_id' => $LOG_FILE_ID,
'log_per_date' => true,
]);
$json_class = 'CoreLibs\Convert\Json';
// define a list of from to color sets for conversion test
$PAGE_NAME = 'TEST CLASS: JSON';
print "";
print "
" . $PAGE_NAME . "";
print "";
print '';
print '' . $PAGE_NAME . '
';
$json = '{"foo": "bar"}';
$output = Json::jsonConvertToArray($json);
print "S::JSON: $json: " . DgS::printAr($output) . "
";
print "S::JSON ERROR: " . Json::jsonGetLastError() . ": " . Json::jsonGetLastError(true) . "
";
$json = '["f: {b"""ar}]';
$output = Json::jsonConvertToArray($json);
print "S::E-JSON: $json: " . DgS::printAr($output) . "
";
print "S::E-JSON ERROR: " . Json::jsonGetLastError() . ": " . Json::jsonGetLastError(true) . "
";
print "S::E Validate: " . Json::jsonValidate($json) . ": " . Json::jsonGetLastError(true) . "
";
// direct
$json = '{"direct": "static function call"}';
$output = $json_class::jsonConvertToArray($json);
print "J/S::JSON: $json: " . DgS::printAr($output) . "
";
print "J/S::JSON ERROR: " . $json_class::jsonGetLastError() . ": " . $json_class::jsonGetLastError(true) . "
";
$json = '["f: {b"""ar}]';
$output = $json_class::jsonConvertToArray($json);
print "J/S::E-JSON: $json: " . DgS::printAr($output) . "
";
print "J/S::E-JSON ERROR: " . $json_class::jsonGetLastError() . ": " . $json_class::jsonGetLastError(true) . "
";
echo "
";
$json = '{"valid":"json","invalid":"\xB1\x31"}';
$json = '{"valid":"json","invalid":"abc\x80def"}';
$output_no_flag = Json::jsonConvertToArray($json);
print "No Flag JSON: $json: " . DgS::printAr($output_no_flag) . "
";
print "No Flag JSON ERROR: " . Json::jsonGetLastError() . ": " . Json::jsonGetLastError(true) . "
";
$output_flag = Json::jsonConvertToArray($json, flags:JSON_INVALID_UTF8_IGNORE);
print "No Flag JSON: $json: " . DgS::printAr($output_flag) . "
";
print "No Flag JSON ERROR: " . Json::jsonGetLastError() . ": " . Json::jsonGetLastError(true) . "
";
$output_raw = json_decode($json, true, flags:JSON_INVALID_UTF8_IGNORE);
print "No Flag JSON RAW (F-1): $json: " . DgS::printAr($output_raw) . "
";
$output_raw = json_decode($json, true, flags:JSON_INVALID_UTF8_SUBSTITUTE);
print "No Flag JSON RAW (F-2): $json: " . DgS::printAr($output_raw) . "
";
$output_raw = json_decode($json, true);
print "No Flag JSON RAW: $json: " . DgS::printAr($output_raw) . "
";
echo "
";
// $json = '{"foo": "bar"}';
// $output = Jason::jsonConvertToArray($json);
// print "S::JSON: $json: " . DgS::printAr($output) . "
";
// print "S::JSON ERROR: " . Jason::jsonGetLastError() . ": " . Jason::jsonGetLastError(true) . "
";
// convert an array to json
$array = ['foo' => 'bar'];
$output = Json::jsonConvertArrayTo($array);
print "S::JSON: " . DgS::printAr($array) . " => " . $output . "
";
$array = ['foo' => 'bar', 'sub' => ['other' => 'this', 'foo' => 'bar', 'set' => [12, 34, true]]];
print "Pretty: " . Json::jsonPrettyPrint($array) . "
";
print "";
// __END__