Valid JSON Formatting
It should be noted that certain characters will need to be escaped in the JSON data for each jQuery DataTable column in order to prevent JSON errors. While JSON only mandates that forward slashes (/) be escaped by a backslash (\/), use of other characters like commas, single quotes, whitespace at the stat of a string, and double quotes can throw off the rendering of the JSON. As a result, the following conversions should be made for any content being returned in the JSON fields (jQuery dataTable columns):
Forward slashes need to be escaped with a backslash. This is commonly an issue with end tags (e.g. </li> would need to be converted to <\/li>)
Double quotes should be converted to "
Single quotes should be converted to '
Commas are generally ok, but can be converted to ,
Carriage returns, chr(13), and line feed characters, chr(10), must be converted or removed for valid JSON.
Here is an example cfc function for filtering content prior to JSON formatting:
Last updated
Was this helpful?