The string you're outputting is wrapped in double-quotes. So the double-quotes inside that string need to be escaped, which is what the backslashes are doing.
You say you have another function doing this that works fine; what's the difference?
- Different returntype or access attributes?
- Are you using single-quotes instead of double-quotes in that function?
- Are you outputting it differently?