Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Strip quotes with JavaScript to convert into JSON object?
For this, you can use replace() along with parse(). Following is the code −
Example
var studentDetails = `"{""name"": ""John"",""subjectName"":
""Introduction To JavaScript""}"`;
console.log("The actual object=");
console.log(studentDetails);
var removeFirstAndLast = studentDetails.substring(1,studentDetails.length-1)
var removeDoubleQuotes = removeFirstAndLast.replace(/""/gi, `"`)
console.log(removeDoubleQuotes)
var output = JSON.parse(removeDoubleQuotes);
console.log(output);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo103.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo103.js
The actual object=
"{""name"": ""John"",""subjectName"": ""Introduction To JavaScript""}"
{"name": "John","subjectName": "Introduction To JavaScript"}
{ name: 'John', subjectName: 'Introduction To JavaScript' }Advertisements