JSFiddle - React, Tailwind, and code Playground
by Liu David
JavaScript
function justifyStringForJson(str) {
var newStr = str.replace(/\\/g, '\\\\');
newStr = newStr.replace(/"/g, '\\"');
newStr = newStr.replace(/[\u200B-\u200D\uFEFF]/g, '');
return newStr;
}
var strTest = '好的"haha人"h\\h\';
alert(justifyStringForJson(strTest));