-2

i have this string:

"{\\'Ovcount\\':\\'0\\',\\'S1\\':\\'LU\\',\\'S2\\':\\'NewClientOrMove\\',\\'memoToDisplay\\':\\'LU -- New Client or Move\\\"}"; 

and i want it to become like this:

'{"Ovcount":"0","S1":"LU","S2":"NewClientOrMove","memoToDisplay":"LU -- New Client or Move"}'

I tried with stringify and replace and i ended up with

"{'Ovcount':'0','S1':'LU','S2':'NewClientOrMove','memoToDisplay':'LU -- New Client or Move"}"

And from here i wanted to replace the single quotation marks ' with double quotation marks " but when i did, in beginning and ending of the string appeared an extra "\

"\ "{"Ovcount":"0","S1":"LU","S2":"NewClientOrMove","memoToDisplay":"LU -- New Client or Move\"}\ ""

Any tips on how to get the correct format?

pilchard
  • 12,414
  • 5
  • 11
  • 23
Dragos
  • 3
  • 2

1 Answers1

1

var result = "{\'Ovcount\':\'0\',\'S1\':\'LU\',\'S2\':\'NewClientOrMove\',\'memoToDisplay\':\'LU -- New Client or Move\"}"
  .replaceAll("'", '"')
  .replaceAll('\\', '');
console.log(result);

this got me what you wanted, it replaces all the single quotes with double quotes, then it removes any back slashes

the result is

'{"Ovcount":"0","S1":"LU","S2":"NewClientOrMove","memoToDisplay":"LU -- New Client or Move"}'

becem
  • 116
  • 3