Strip Slashes from JSON object


#1

Hello,
I have the following data,

var data = {"\id\":"\23232\","\pass\":"\1434\"}

All i want to do is to strip the backslashes. Javascript’s replace function doesn’t work.

var outputData = {"id":"23232","pass":"1434"}

Any Help?


#2

I think this link little help remove strip tag slashes


#3

Don’t get me wrong but this is the Ionic Framework forum.

This question should be asked at StackOverflow.

P.S. Like @junaidy told you use Regular Expressions. Learn them if you don’t know then, you can’t call yourself a developer if you don’t know how to use Regex.


#4

oh sorry but this is may be help, and you only convert to json again

    var data = {"\\id\\":"\\23232\\","\\pass\\":"\\1434\\"};
    console.log(data);
    var b=JSON.stringify(data);
    str = b.replace(/\\/g, '');
    console.log(str);

#5

Nice, simplest solutions are best. I would only put it all in a single line.