What is the correct way to escape text in JSON responses?
Question
I am generating the json from PHP.
Solution
The correct way is to use json_encode()
OTHER TIPS
The JSON is just a subset of Javascript, so everything you know about escaping strings in Javascript applies to JSON.
And yes, the correct answer is to use one of library functions, there is a quite a few of them around: see A completely fair and balanced comparison of php json libraries.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow