How to Remove JSON Backslash in Javascript?

Nov 09, 2022 . Admin



Hello friends,

This simple article demonstrates how to remove JSON backslash in javascript. This article will give you a simple example of removing JSON backslash with an example. you can understand the concept of removing backslash in javascript. We will use remove all backslash of JSON in javascript. you will do the following things to remove JSON backslash in javascript.

To remove the backslash, you can use JSON.stringify() and replace() to remove the backslash in javascript. We have seen how to remove JSON backslash with an example.

So, let's see bellow solution:

Example:
index.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>How to Remove JSON Backslash in Javascript?</title>
</head>
<body>
<script type="text/javascript">

    //create jsonPlayer
    var jsonPlayer = {
        Firstname:"\\Rohit\\",
        Lastname:"\\Sharma\\",
    }
    
    //convert json Player stringify
    var player=JSON.stringify(jsonPlayer);
    
    //get string json data stringify
    str = player.replace(/\\/g, '');
    
    //print remove backslash
    console.log(str);

</script>
</body>
</html>
Check The Console For Output:
{"Firstname":"Rohit","Lastname":"Sharma"}

I hope it will help you...

#Javascript