function Json::canonicalize
To allow comparison of JSON strings, first process them into a consistent format so that they can be compared as strings.
Return value
array ($error, $canonicalized_json) The $error parameter is used to indicate an error decoding the json. This is used to avoid ambiguity with JSON strings consisting entirely of 'null' or 'false'.
2 calls to Json::canonicalize()
- JsonMatches::fail in vendor/
phpunit/ phpunit/ src/ Framework/ Constraint/ JsonMatches.php - Throws an exception for the given compared value and test description.
- JsonMatches::matches in vendor/
phpunit/ phpunit/ src/ Framework/ Constraint/ JsonMatches.php - Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.
File
-
vendor/
phpunit/ phpunit/ src/ Util/ Json.php, line 52
Class
- Json
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\UtilCode
public static function canonicalize(string $json) : array {
$decodedJson = json_decode($json);
if (json_last_error()) {
return [
true,
null,
];
}
self::recursiveSort($decodedJson);
$reencodedJson = json_encode($decodedJson);
return [
false,
$reencodedJson,
];
}