I am trying to prove that if $f: \mathbb R^n \to \overline{\mathbb R}$ is measurable, then there exists $g: \mathbb R^n \to \overline{\mathbb R}$ Borel measurable such that $f=g$ a.e. I know this problem has been asked here somewhere but I couldn't understand the solutions so I'll write what I could think of:
Since $\mathbb Q$ is dense, notice that $\mathbb R=\bigcup_{q \in \mathbb Q} \{f>q\}$. Given $q$ a rational number, $$\{f>q\}=F_q \cup Z_q$$
with $F_q$ an $F_{\sigma}$ set and $Z_q$ of zero measure.
We can write $\mathbb R=(\bigcup_{q \in \mathbb Q} F_q) \cup (\bigcup_{q \in \mathbb Q} Z_q)$
I define $$g(x)=\begin{cases} f(x) &\text{if }x \in \mathbb{\bigcup_{q \in \mathbb Q} F_q} \\ 0 & \text{if not} \\ \end{cases}$$
I was trying to show that $g$ is borel measurable, and since for $a \in \mathbb R$, $\{g>a\}=\bigcup_{q \geq a, q \in \mathbb Q} \{g>q\}$, it is enough to show that $\{g>q\}$ is a borel set for $q$ rational. My $g$ doesn't work since for $q \geq 0$, $$\{g>q\}=\{f>q\},$$
and for $q<0$, $$\{g>q\}=\{f>q\} \cup \{g=0\}$$
and none of these sets is necessarily a borel subset.
I would appreciate some help with this problem. Thanks in advance.