If $J$ is empty or a singleton, then the claim is vacuously true, so assume $J$ has at least two elements and let $i, j \in J$ such that $i \neq j$. Since $J$ is an ordered set and since $i$ and $j$ are distinct, we may assume without loss of generality that $i < j$. Since $X$ is a martingale on $P$, then $\mathbb{E}(X_j \mid \mathcal{G}_i) \overset{a.s.}{=} X_i$ and thus
\begin{equation}
\mathbb{E}(\mathbb{E}(X_j \mid \mathcal{G}_i)) = \mathbb{E} (X_i)
\end{equation}
On the other hand, result
R2150: Expectation of conditional expectation for a random euclidean real number shows that
\begin{equation}
\mathbb{E}(\mathbb{E}(X_j \mid \mathcal{G}_i)) = \mathbb{E}(X_j)
\end{equation}
Combining the above two equations then gives
\begin{equation}
\mathbb{E} (X_i)
= \mathbb{E}(\mathbb{E}(X_j \mid \mathcal{G}_i))
= \mathbb{E}(X_j)
\end{equation}
This finishes the proof. $\square$