I am generating the json from PHP.
Right, *you* wouldn't ever want to escape the text, you let the library do it
Gareth
2008-10-31 10:18:56
For the Googling masses: json_escape() misses many important characters that will choke up a super-strict JSON validator (iPhone JSON libraries in my experience; errors not found by jslint.com or jsonlint.com). Examples are tabs and returns \t \r
editor
2010-08-27 02:35:32
+1
A:
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.
Stepan Stolyarov
2008-10-31 10:26:44