[step:Apply Coarea Change of Variables to the weight $h = g/|\nabla f|$ on the regular set]
Define the regular and critical sets
\begin{align*}
R &:= \{x \in \mathbb{R}^n : |\nabla f(x)| > 0\}, \\
C &:= \{x \in \mathbb{R}^n : |\nabla f(x)| = 0\} = \mathbb{R}^n \setminus R.
\end{align*}
Both $R$ and $C$ are Borel sets because $|\nabla f|: \mathbb{R}^n \to [0, +\infty)$ is Borel measurable (as established in Step 1).
Define the weight
\begin{align*}
h: \mathbb{R}^n &\to [0, +\infty] \\
x &\mapsto \begin{cases} g(x)/|\nabla f(x)| & \text{if } x \in R, \\ 0 & \text{if } x \in C. \end{cases}
\end{align*}
We verify $h$ is $\mathcal{L}^n$-measurable: on the Borel set $R$, $h = g \cdot (1/|\nabla f|)$ is measurable as the product of the measurable function $g$ and the measurable function $1/|\nabla f|$ (the reciprocal of a positive measurable function); on the Borel set $C$, $h \equiv 0$. Gluing these on the disjoint union $R \sqcup C = \mathbb{R}^n$ gives a measurable $h$. Non-negativity $h \ge 0$ follows from $g \ge 0$ and $|\nabla f| > 0$ on $R$.
We now invoke the [Coarea Change of Variables](/theorems/3079) with parameters $A := \mathbb{R}^n$, $k := 1$, ambient dimension $n \ge 1$, the Lipschitz map $f: \mathbb{R}^n \to \mathbb{R}$, and the weight $h$. The hypotheses of Theorem 3079 are: (i) $f$ Lipschitz from $\mathbb{R}^n$ to $\mathbb{R}^k$ with $n \ge k$ — verified, $k = 1$, $n \ge 1$; (ii) $A \subseteq \mathbb{R}^n$ is $\mathcal{L}^n$-measurable — verified, $A = \mathbb{R}^n$; (iii) $h: A \to [0, +\infty]$ is $\mathcal{L}^n$-measurable — verified above. Theorem 3079 yields
\begin{align*}
\int_{\mathbb{R}^n} h(x) \, J_1 f(x) \, d\mathcal{L}^n(x) = \int_{-\infty}^{\infty} \int_{f^{-1}(t)} h(x) \, d\mathcal{H}^{n-1}(x) \, d\mathcal{L}^1(t),
\end{align*}
together with $\mathcal{L}^1$-measurability of the inner integral $t \mapsto \int_{f^{-1}(t)} h \, d\mathcal{H}^{n-1}$.
We compute each side. For the left side, partition $\mathbb{R}^n = R \sqcup C$:
\begin{align*}
\int_{\mathbb{R}^n} h \cdot J_1 f \, d\mathcal{L}^n &= \int_R h \cdot J_1 f \, d\mathcal{L}^n + \int_C h \cdot J_1 f \, d\mathcal{L}^n.
\end{align*}
By the definition of $h$, the integrand vanishes on $C$, so the second integral is $0$. On $R$, by Step 1 we have $J_1 f = |\nabla f|$ at $\mathcal{L}^n$-a.e. point, so
\begin{align*}
h(x) \, J_1 f(x) = \frac{g(x)}{|\nabla f(x)|} \cdot |\nabla f(x)| = g(x) \qquad \text{for } \mathcal{L}^n\text{-a.e. } x \in R.
\end{align*}
Therefore the left side equals $\int_R g \, d\mathcal{L}^n$, which is precisely $\int_{\{|\nabla f| > 0\}} g \, d\mathcal{L}^n$.
For the right side, the inner integrand is $h(x)$, which on the level set $f^{-1}(t)$ takes the value $g(x)/|\nabla f(x)|$ at points in $R$ and $0$ at points in $C$, in accordance with the convention adopted in the theorem statement. So the right side is exactly
\begin{align*}
\int_{-\infty}^{\infty} \int_{f^{-1}(t)} \frac{g(x)}{|\nabla f(x)|} \, d\mathcal{H}^{n-1}(x) \, d\mathcal{L}^1(t),
\end{align*}
provided that this expression is well-defined, i.e., that the convention $g/|\nabla f| = 0$ on $C$ does not introduce ambiguity. We address this in Step 3.
[/step]