I have a web app in which I allow some large text entry using text fields. This text is saved to a database and then later it is sent back to the user as a field in a JSON response. In the browser, I attempt to simply convert it to an Object
using JSON.parse
, but this sometimes fails depending on what the user put in the field.
I think that right now, the text has single quotes in it, and those are breaking the browser-side Javascript before I can call JSON.parse
on it.
What's the best way to sanitize this data so that, ideally, I can just parse it back to an Object
with minimal cleansing after it has been saved?