JSON.parse incorrect string format

Tutorial: JSON.parse incorrect string format

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?

Solution 1: JSON.parse incorrect string format

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

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

the result is

‘{“Ovcount”:”0″,”S1″:”LU”,”S2″:”NewClientOrMove”,”memoToDisplay”:”LU — New Client or Move”}’

Solution 2: JSON.parse incorrect string format

Try this, It might work!

let str = "{\'Ovcount\':\'0\',\'S1\':\'LU\',\'S2\':\'NewClientOrMove\',\'memoToDisplay\':\'LU -- New Client or Move\"}";
let result = str.replace(/\\/g, "");
console.log(result.replace(/'/g, '"'));


I hope the JSON.parse incorrect string format Solution would be useful for you to learn something new from this solution. If it helped you then don’t forget to bookmark our site for more Quiz Answers and solutions.

check out on stack overflow

Leave a Reply

Your email address will not be published.