diff --git a/src/utils/jsonToHtml.ts b/src/utils/jsonToHtml.ts
index bbdc638e55..59edc47c79 100644
--- a/src/utils/jsonToHtml.ts
+++ b/src/utils/jsonToHtml.ts
@@ -20,8 +20,8 @@ function htmlEncode(t) {
: '';
}
-function escapeForStringLiteral(str: string) {
- return str.replace(/([\\"])/g, '\\$1');
+function stringifyStringLiteral(str: string) {
+ return JSON.stringify(str).slice(1, -1);
}
function decorateWithSpan(value, className) {
@@ -56,11 +56,11 @@ function valueToHTML(value, maxExpandLevel: number) {
'' +
- htmlEncode(escapeForStringLiteral(value)) +
+ htmlEncode(stringifyStringLiteral(value)) +
'' +
decorateWithSpan('"', 'token string');
} else {
- output += decorateWithSpan('"' + escapeForStringLiteral(value) + '"', 'token string');
+ output += decorateWithSpan('"' + stringifyStringLiteral(value) + '"', 'token string');
}
} else if (valueType === 'boolean') {
output += decorateWithSpan(value, 'token boolean');