src/Validate.php
public static function asJson($data, $default = null)
    {
        $json = is_string($data) ? $data : json_encode($data);

        return $json !== false ? $json : $default;
    }
public static function asJson($data, $default = null)
    {
        $json = is_string($data) ? $data : json_encode($data);

        return $json !== false ? $json : $default;
    }
Parameter return as JSON.

@param mixed $data    → data to convert
@param mixed $default → default value in error case

@return mixed → value, null or customized return value