I have a doubt that involves Hilbert spaces and diagonalisation. So if we say that a diagonal operator in a basis can be written as, (with Dirac's notation)

$$A=\sum a\_i |i\rangle \langle i|$$

In any space I know that this diagonalisation condition can be more complicated. But in a Hilbert space when a operator is expressable as I written before? Can I always write an operator in this form?

It's known that if the operator is hermitian, is diagonalisable. But as fas as I know this condition is not necessary and sufficient, and I don't know what restrctions can be imposed to matrixes in a Hilbert space.

I have not specified the dimension, so there could be some difference bethen the finite and infinite dimensions.