public static function maybeDecode($value, $asArray = false)
    {
        if (!is_string($value)) {
            return $value;
        }

        $decoded = json_decode($value, $asArray);

        if (json_last_error() == JSON_ERROR_NONE && (is_object($decoded) || is_array($decoded))) {
            return $decoded;
        } else {
            // Reset the JSON error code:
            json_decode("[]");

            return $value;
        }
    }