When generating JSON to be included directly in an HTML file, it's important to wrap the JSON in a JavaScript string. For example:
var dataContacts =
'{"Contacts":[{"Id":0,"Active":false,"Company":"Rory The Architect\\, Melt"}]}';
var contacts = $.parseJSON(dataContacts).Contacts;
This code may fail in JavaScript because it should actually be written as:
var dataContacts =
'{"Contacts":[{"Id":0,"Active":false,"Company":"Rory The Architect\\\\, Melt"}]}';
var contacts = $.parseJSON(dataContacts).Contacts;
It seems that neither .NET Serializer nor NewtonSoft.Json have support for converting "\" to "\\", which is necessary for embedding JSON within a JavaScript string.
To address this issue, consider using something like myJson.Replace("\", "\\");
For more information on why double escaping for backslashes is needed, check out this link:
Why does the jQuery JSON parser need double escaping for backslashes?
The first escape escapes it in the Javascript string literal. The second escape escapes it in the JSON string literal.
The Javascript expression '{"a":"b:\c"}' evaluates to the string '{"a":"b:\c"}'. This string contains a single unescaped \, which must be escaped for JSON. In order to get a string containing \, each \ must be escaped in the Javascript expression, resulting in "\\".
If you're unsure of the best approach moving forward with this issue, and why there is no built-in support for encoding JSON for direct inclusion into a JavaScript file by NewtonSoft or the .NET serializer, it might require further investigation.