There are several approaches you can take for converting between cartesian and spherical tensors. You can start with the definition of spherical vectors:
$$ \hat e^{\pm} = \frac 1 2 \mp[\hat x \pm i\hat y]$$
$$ \hat e^0 = \hat z $$
and then make a correspondence with vector spins, $|j,m\rangle$:
$$ \hat e^{\pm} \rightarrow |1,\pm 1\rangle$$
$$ \hat e^0 \rightarrow |1, 0\rangle$$
and use Clebsch-Gordan coefficients to compute the addition of two vector spins, and then map those to spherical tensors:
$$ |J,M\rangle \rightarrow T_M^J $$
For example:
$$ |2, 2\rangle = |1,1\rangle|1,1\rangle$$
which means we can express a unit $T_2^2$ as a dyad:
$$ \hat T_2^2 = e^+e^+=\frac 1 2 (-\hat x+i\hat y)(-\hat x+i\hat y) = \frac 1 2[\hat x\hat x - \hat y\hat y - i(\hat x\hat y+\hat y\hat x)] $$
So you can do that for every combination and invert the equations.
Or: you can look at Spherical harmonics in cartesian coordinates and then convert that to dyad (but only for natural form tensors):
$$ T_1^2 \rightarrow Y_2^1 \propto -(x-iy)z \rightarrow -\hat xz + i\hat y z$$
and go from there, but normalizations and signs might no be as clear.
The result is that cartesian to spherical is as follows: The isotropic part is the trace of the cartesian tensor:
$$ T_0^0 = \frac 1 3 T_{ii} $$
The J=1 are all from the antisymmetric part:
$$ T_0^1 = \sqrt{\frac 1 2}[T_{xy}-T_{yx}] $$
$$ T_{\pm 1}^1 = \mp \sqrt{\frac 1 2}[(T_{yz}-T_{zy})\pm i(T_{zx}-T_{xz}) ] $$
For the pure rank-2, aka natural form, you start with the symmetric trace free part:
$$ S_{ij} = \frac 1 2 [T_{ij}-T_{ji}] - \frac 1 3 T_{ii}\delta_{ij}$$
as follows:
$$ T_{\pm 2}^2 = \frac 1 2 [S_{xx}-S_{yy}\pm 2iS_{xy}]$$
$$ T_{\pm 1}^2 = \frac 1 2 [S_{xz}+i S_{yz}]$$
$$ T_0^2 = \sqrt{\frac 3 2}S_{zz}$$
The inversion of the pure rank 2 should be:
$${\bf S} = \left [ \begin{array}{ccc}T_2^2+T_{-2}^2-\sqrt{\frac 2 3}T_0^2 &
-i(T_2^2-T_{-2}^2) & -T_1^2+T_{-1}^2 \\ -i(T_2^2-T_{-2}^2) &
-T_2^2-T_{-2}^2-\sqrt{\frac 2 3}T_0^2 & i(T_1^2+T_{-1}^2)\\ -T_1^2+T_{-1}^2
& i(T_1^2+T_{-1}^2) & \sqrt{\frac 8 3}T_0^2 \end{array} \right ]$$
At higher rank, $N$, it gets difficult: you have to use standard young tableaux with $N$ boxes to get the
irreducible representations of the permutation group on $N$ letters. Each of those, when applied to the indices, corresponds to a unique $T_M^J$ subspace (Schur-Weyl Duality).
At rank 3, you find:
$$ \bf 3 \otimes 3 \otimes 3 = 7_S \oplus 3_S \oplus 5_M \oplus 3_M \oplus 5_M \oplus 3_M \oplus 1_A$$
where the subscripts refer to symmetric, mixed, and antisymmetric in indices, and the numbers are the dimension of the spherical tensor: $2J+1$.
So, for instance, $\bf 1_A$, is isotropic an proportional to $\epsilon_{ijk}$.
Meanwhile, the total symmetric part has 10 dimensions, 7 of which are pure rank, and 3 of which transform like a vector. To work that out, you start with the
totally symmetric combinations of indices:
$$ S_{ijk} = \frac 1 6 [T_{ijk} +T_{ski} +T_{kij} +T_{kji} +T_{ikj} +T_{jik}]$$
and subtract the trace:
$$ N_{ijk} = S_{ijk} - \frac 3 5 \delta_{ij}V_k$$
where:
$$ V_k = S_{iij} = S_{iji} = S_{jii} $$
becomes one of the $T_M^1$ components.
The pure rank 3 solution is:
$$T_{\pm 3}^3 = \frac 1 {\sqrt 8}[(-N_{xxx}+3N_{xyy})\mp iN_{yyy}] $$
$$T_{\pm 2}^3 = \frac 1 2[N_{xxz}-N_{yyz})\mp 2iN_{xyz}] $$
$$T_{\pm 1}^3 = \frac {\sqrt 15}3\big [ \frac 1 {\sqrt 2}[\mp N_{xzz}-iN_{yzz}]+ \frac 1 {\sqrt 8} [\mp(N_{xxx}-N_{xxy})+ i(N_{yyy}\pm N_{xxy})]\big ] $$
$$T_0^3 = \frac{\sqrt{10}} 3[\frac 1{\sqrt 2}(N_{xzz}-iN_{yzz})+ N_{zzz}]$$
The (anti-)symmetric tensor correspond to the index permutation derived from the standard Young Tableaux from the integer partitions of $(1+1+1=3)$ and $3=3$, which is similar to the rank two case.
The mixed symmetry rotationally invariant subspaces correspond to $3=2+1$, for which there are two standard Tableaux, leading to:
$$T^{(0,1;2)}=\frac 1 3 [T_{ijk}+T_{jik}-T_{kji}-T_{kij}] $$
$$T^{(0,2;1)}=\frac 1 3 [T_{ijk}+T_{kji}-T_{jik}-T_{jki}] $$
Each of these has 8 = 3 + 5 degrees of freedom, corresponding to a $J=2$ and $J=1$ part. The vector part ($J=1$) is found by taking the non-zero trace:
$$ v^1_i = T^{(0,1;2)}_{ijj} = - T^{(0,1;2)}_{jji} $$
$$ v^2_i = T^{(0,2;1)}_{ijj} = - T^{(0,2;1)}_{jij} $$
Those can be subtracted (with suitable a outer product with $\delta_{ij}$) to leave a 5 DoF object that transforms like a rank-2 tensor.