How to escape JSON string?

theringostarrs picture theringostarrs · Aug 7, 2009 · Viewed 148.7k times · Source

Are there any classes/functions available to be used for easy JSON escaping? I'd rather not have to write my own.

Answer

xmedeko picture xmedeko · Jun 15, 2016

I use System.Web.HttpUtility.JavaScriptStringEncode

string quoted = HttpUtility.JavaScriptStringEncode(input);